#C++ if/else keeps failing

24 messages · Page 1 of 1 (latest)

proud breach
#
int messageLetters;//the numbers of each ASCII letter, e.g. 65 = A

    cout << "Enter message code: ";
    cin >> messageLetters;

    if (messageLetters > 0 && <= 128);
    {
        cout << char(messageLetters) << "|";
    }
    else
    {
        cout << char(0);
    }

Whenever I run the debugger, it says the there's an illegal if without an appropriate else. The 2nd "cout" also isn't recognized as that. The "<=" is also giving me an "expected a expression" error.

I'm trying to get it to where you type in ASCII numbers and get the appropriate letters, symbols, etc.

round crescentBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

steady thunder
#

youre not supposed to have ; after the if()

proud breach
#

So, just if messageLetters....

#

Or should I put it in the function?

steady thunder
#

if(expression){...}else{...}

proud breach
#

messageLetters > 0 && <= 128
Is this not an expression? if messageLetters is greater than 0 and less than or equal to 128
(I'm sorry. I really am trying to understand)

full radish
#

the issue is that the semicolon marks the termination of a statement

#

so your if applies to that (nothing) instead of the block which begins on the next line with the curly braces

proud breach
full radish
#

yeah this is the compiler getting confused because your condition is also wrong

proud breach
#

Yes, I know I like it colorful

full radish
#

it's supposed to be if (messageLetters > 0 && messageLetters <= 128)

full radish
proud breach
full radish
#

didn't you mispell it?

#

it's the only way to write what you want

proud breach
#

cheems
I think it hates me. NOW it's fine

full radish
#

hehe

#

no worries, glad it's solved cat_up

proud breach
#

Thank you

#

!solved