Evaluating input character values

I have a program that I am trying to determine if one of the input characters is an h, c, or i. Its using <iostream> and namespace std;

cout << "Enter account #, code and gallons used: ";
cin >> account, code, gallons;

if (code == h || code == c || code == i)
void (function i need to run)
else
cout << "Invalid code input" << endl << endl;

I can't seem to get the letters evaluated whatever I do, any help would be appreciated
by cin >> account, code, gallons; do you mean cin >> account >> code >> gallons;

also I think if (code == h || code == c || code == i) should be if (code == 'h' || code == 'c' || code == 'i')
Make sure code is declared with a type of char.
When you compare it, the literal values must be enclosed in single quotes.
1
2
3
4
5
6
7
    char code;
    cin >> code;

    if (code == 'h' || code == 'c' || code == 'i')
    {
        etc.
    }
I had code as type char, I did not have the single quotes and had the input formatting wrong. Didn't do cin >> account >> code >> gallons; the red lines have disappeared for now so hopefully it should run okay now. Thanks.
Topic archived. No new replies allowed.