I dont get how I keep messing up toupper. I want to understand it but jesus, everytime I use it, it never works. In this code I guess I did something wrong with it. answer = (char)toupper(0);. Ive asked for help on toupper on another forum of mine, but I guess I wont be able to understand it.
Isnt toupper suppose to be... theVariable=(type)toupper(letter_you_want_to_change)? If not then what did I do wrong?
A string is basically a char array. You want to take the first element of the array and check if it's a lower case letter. If it is, make it into an upper case letter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
string word;
cout << "Enter a word (First letter should be lower case) ";
getline(cin, word);
cout << "Word before check: " << word << endl;
if (islower(word[0]))
word[0] = toupper(word[0]);
cout << "Word after check: " << word << endl;
}