How do I call a bool function in main?

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
using namespace 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?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

bool IsAlphaHigher( const char& letterOne, const char& 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";
    }
}
Last edited on
Topic archived. No new replies allowed.