Why doesn't the following program change a sentence to uppercase?
#include <iostream>
#include <string>
using namespace std;
int main()
{
char name[20];
cout << "what is your name?" << endl;
system("pause");
cin.get(name, 20);
name[20] = toupper(name[20]);
cout << "Your name is " << name<< endl;
system("pause");
}
You have to convert each character to upper-case,
name[20]only gets the index20(which, in your case is an invalid index too).You can loop through the array to convert each character to upper-case.
You should also see this thread: Why is "using namespace std" considered bad practice?