Im currently doing an excercise where if the user enters two letters, A and B for example, it will output that A is higher than B on the alphabet. This is my first bool function and Im not quite sure how to actually use what I'm returning from my Bool function in main.
usingnamespace std;
#include <iostream>
bool IsAlphaHigher(char letterOne, char letterTwo);
int main()
{
cout << "Enter two letters ";
cin >> letter1 >> letter2;
IsAlphaHigher(letter1, letter2);
if (IsALphaHigher() == true)
cout << "letter1 is higher on the alphabet than letter2";
}
bool IsAlphaHigher(char letterOne, char letterTwo)
{
if (letterOne > 90) letterOne -= 32;
if (letterTwo > 90) letterTwo -= 32;
return letterOne < letterTwo; // true if letterOne is lower.
}
I want to use an If statement, If whats being returned from the function is True than output Letter1 is higher than Letter2, but how do I actually use the true thats being returned in a boolean function? What am I doing wrong in Main?
#include <iostream>
bool IsAlphaHigher( constchar& letterOne, constchar& letterTwo)
{
return letterOne > letterTwo;//the return value corresponding to bool
}
//current version of the function is not case insensitive, so a is higher than A
//can make it case insensitive by tolower()
int main()
{
char letter1;//usually good practice to avoid multiple variable declarations in one statement
std::cout << "Enter first letter: \n";
std::cin >> letter1;
char letter2;
std::cout << "Enter second letter: \n";
std::cin >> letter2;
if(IsAlphaHigher(letter1, letter2))//can pass the function to if() directly
{
std::cout << "letter1 is higher on the alphabet than letter2\n";
}
else
{
std::cout << "letter2 is higher on the alphabet than letter1 \n";
}
}