Is there a way that whether user input "a" in small caps or large caps in console but program runs it as follows instead of writing "a" with both small and large caps in program
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string alp;
cout << "Enter an alphabet: ";
cin >> alp;
// Referring to below command
if (alp == "a" || alp == "e" || alp == "i" || alp == "o" || alp == "u" ||
alp == "A" || alp == "E" || alp == "I" || alp == "O" || alp == "U")
{
cout << alp << " is vowel.";
}
else
{
cout << alp << " is consonant.";
}
cout << endl << endl;
}
You can use toupper() to convert to uppercase and tolower() to convert to lower case. You need to #include <cctype> at the beginning. Note it works on only a single char, not a string.
const just means that the value doesn't change - is constant - so the compiler can check that it doesn't. It's good practice to make any initialised variable const if the value doesn't/shouldn't change.
Don't worry about it now. You can leave out const and the program will still work ok.
How did it work? What did you change? The program you send here before is same as this one instead of adding const and changing name. How could it print large caps?
Unless you have more program to add then you can overcome the change by relocating where alp is printed out. alp gets changed as required but nobody will ever know.