Do you know how to read a string of text from the user?
Do you know how to write a for loop?
Do you know how to convert a single character to upper case?
Do you know how to access individual characters in a string?
If the answer to any of those questions is "no", then you need to spend some time learning and understanding the basic concepts (That means you need to take some time out to read your notes/book(s) and tutorials, and you need to try writing simpler programs which you can understand).
You won't learn by stabbing in the dark when you're already missing some of the basics, so save yourself the wasted time and frustration by making sure you understand the basics first.
//This function accepts any string and Capitolizes the first character
string Capitolize(string input)
if (input <= 'z' && output >= 'a')
input -= 0x20; //Convert to upper, ref: http://www.asciitable.com/return input;
int main ()
cout << "Please type a sentence \n";
getline(cin,Sentence); // Using getline so we can include whitespaces
cout<<Capitolize(Sentence); // cout the result of a capitolized sentence
constint MAX_LENGTH = 500;
bool cap_it = true;
std::cout << "Write a sentence and the first letter of each word will be capitalized for you.\n";
for (int i = 0; i < strlen(sentence); i++)
if (isalpha(sentence[i]) && cap_it == true)
sentence[i] = toupper(sentence[i]);
cap_it = false;
elseif (isspace (sentence[i]))
cap_it = true;
std::cout << std::endl << sentence << std::endl;
How exactly do you think you're helping anybody by spoon-feeding somebody a solution to their homework? The point of these forums is to assist beginners in learning - it's not helpful at all to hand out code to someone who either lacks understanding (And therefore isn't going to get that understanding from just copying a bit of code from the internet) or is plainly too lazy to spend their own time studying and practising.
In fact it's entirely counter-productive; not least because it encourages posters to keep on "begging" others to do their work for them without making the effort to learn anything themselves, and because the next time the poster comes across a more difficult problem which they can't solve, they'll be even more stuck since they've already got gaps in their understanding from when they missed out the last time. Please don't do it again.