Hi so im trying to write a program where one inputs a character and the output tells you where the letter stands in the alphabet and also the write suffix for the number. For ex: c=3rd letter of the alphabet
I need it to work for both upper and lower case characters.
I am doing this way but it seems very long and tedious, is there another way where i can just pull out the number of the character and also the suffix?
#include <iostream>
int main() {
char faveChar;
//prompt user for input
cout << "Input your favorite character:\n";
cin >> faveChar;
//If it's a letter, print out where it is in the alphabet & proper suffix
if (faveChar == 'a' || faveChar == 'A')
cout << faveChar << " is the 1st letter of the alphabet.\n";
elseif (faveChar == 'b' || faveChar =='B')
cout << faveChar << " is the 2nd letter of the alphabet.\n";
elseif (faveChar == 'c' || faveChar =='C')
cout << faveChar << " is the 3rd letter of the alphabet.\n";
elseif (faveChar == 'd' || faveChar =='D')
cout << faveChar << " is the 4th letter of the alphabet.\n";
}
#include <iostream>
#include <cctype>
int main ()
{
char c='c';
std::cout<<toupper(c)-'A'+1<<std::endl;
return 0;
}
toupper will convert your character to upper case. If you subtract 'A' will get you the distance between your given character and the first character in the alphabet. so if you input 'a', the answer of toupper(c)-'A' will be 0. So you should add 1