I know this forum may be encounter this age old problem several times, but I just want to understand how to properly execute the code required to accomplish this task.
Right now, I want to limit the use of my code to the following libraries:
-iostream
-cctype
-string
-iomanip
Also, I would like to avoid creating any user defined functions.
I understand that I will require functions such as toupper[] to convert the letters to uppercase letters, a for loop to evaluate each word of the sentence, and something like a counter to only capitalize the first letter of the word being evaluated.
This is currently what my code looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
using namespace std;
int main()
{
char sentence[80];
char title;
cout << "Please enter a title." << endl;
cin.getline(sentence, 80);
title = toupper(sentence[0]);
cout << title << endl;
return 0;
}
|
I understand that by identifying "title" as a char variable, it will only return the first character of the word that's read, despite using getline to read the whole user input.
So far I've been able to build several complex programs, but for some reason I get hung over by the use of strings, so I would appreciate any pointers.