Boolean True False Help

I'm not sure what to do, kinda stuck so need your help.
- I need to write a boolean function, Error, that takes letter and returns true if
letter is not uppercase C,F, or Q and false otherwise.
- If letter is not correct, write an error message and prompt again to enter the
right letter. That's all.
I need to run the program with c 0 and X 100 and check results for both.
I know when i type c i should get an error prompt and when I type X to get a prompt to write the right letter, but not sure how.
Here is the program I have so far:

#include <iostream>
using namespace std;

int ConvertedTemp(int tempIn, char letter);
// If letter is a 'C,' tempIn is converted from Celsius
// to Fahrenheit; otherwise tempIn is converted from
// Fahrenheit to Celsius.

int main ()
{
char letter; // Place to store input letter
int tempIn; // Temperature to be converted

cout << "Input Menu" << endl << endl;
cout << "F: Convert from Fahrenheit to Celsius" << endl;
cout << "C: Convert from Celsius to Fahrenheit" << endl;
cout << "Q: Quit" << endl;
cout << "Type a C, F, or Q; then press return." << endl;

cin >> letter;
while (letter != 'Q')
{
cout << " Type an integer number, and press return."
<< endl;
cin >> tempIn;

if (letter == 'F')
cout << "Fahrenheit to Celsius" << endl;
else
cout << "Celsius to Fahrenheit" << endl;
cout << "Temperature to convert: " << tempIn << endl;
cout << "Converted temperature: "
<< ConvertedTemp(tempIn, letter) << endl << endl;

cout << "Type a C, F, or Q; then press return." << endl;

cin >> letter;
}
return 0;
}

// *****************************************************

int ConvertedTemp(int tempIn, char letter)
{
if (letter == 'C')
return (9 * tempIn / 5) + 32;
else
return 5 * (tempIn - 32) / 9;
}
What function are you having the problem?
boolean.. i need to add boolean code into my program to give out those error messages
Your program is a mess, I think.
1
2
3
4
cout << "F: Convert from Fahrenheit to Celsius" << endl;
cout << "C: Convert from Celsius to Fahrenheit" << endl;
cout << "Q: Quit" << endl;
cout << "Type a C, F, or Q; then press return." << endl;

What does this line mean?
Well once when the program is done and when i run it, it asks to either type C (celsius) or the others and then asks for an integer, and then it just converts to Fah. or vice versa. But that's only while running the program.
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
30
#include <iostream>

bool valid( char c ) { return c == 'C' || c == 'F' || c == 'Q' ; }

int main()
{
    char choice ;

    do
    {
        std::cout << "Input Menu\n---------\n"
                  << "F: Convert from Fahrenheit to Celsius\n"
                  << "C: Convert from Celsius to Fahrenheit\n"
                  << "Q: Quit\n\n" ;

        while( std::cout << "enter C, F, or Q: " && std::cin >> choice && !valid(choice) )
            std::cout << "error: invalid input\n" ;

        if( choice == 'F' )
        {
            // TO DO: convert Fahrenheit to Celsius
        }

        else if( choice == 'C' )
        {
            // TO DO: convert Celsius to Fahrenheit
        }

    } while( choice != 'Q' ) ;
}
Topic archived. No new replies allowed.