# HELP: "expected expression before '>=' token" error, cant figure out whats wrong???

• 08-08-2012
Korben
HELP: "expected expression before '>=' token" error, cant figure out whats wrong???
I've been fixing bugs and errors for hours and now have a raging migraine. I finally got my script from about 12 errors down to one, and I just for the life of me can't figure out what is wrong.

I get this error when compiling:
Attachment 11892

it says "error: expected expression before '>=' token. Any idea what is going on here?

Thank you.

P.S. no I'm not in the class, I'm using the open course material to learn programming and following along on my own.

Code:

``` #include <stdio.h>#include <cs50.h>int main(void) {int MonthNum;long long Pennies;    /* ask user for total days in the month */do {    printf("Enter total days in the month: \n");        MonthNum = GetInt();}while (MonthNum <= 27 || >= 32);    /* ask user for starting amount of pennies */do {    printf("Starting number of pennies on Day 1: \n");        Pennies = GetInt();}while( Pennies <1 );/* calculate total pennies earned over a month */for(int i = 0; i < MonthNum-1; i++) {    Pennies = Pennies * 2;}    /* turn total pennies into dollars */Pennies = Pennies / 100;    /* display money to screen */printf("You made a total of \$%lld \n", Pennies);return 0;} ```
• 08-08-2012
std10093
line 11 should be
Code:

`while(MonthNum<=27 || MonthNum>=32)`
• 08-08-2012
oogabooga
This
Code:

`while (MonthNum <= 27 || >= 32);`
needs to be this
Code:

`while (MonthNum <= 27 || MonthNum >= 32);`
• 08-09-2012
Korben
Awesome! That was it! I didn't realize you have to put the variable on each side of the condition, I don't remember having to do that with other languages. Thank you guys, after spending half the day figuring it out and fixing about a dozen errors, that was the one I couldn't figure out and now it works!!!! Thank you :cool:

Attachment 11895
• 08-09-2012
christop
I can't think of any language that lets you omit the variable like that. What languages are you thinking of?
• 08-09-2012
laserlight
Quote:

Originally Posted by christop
I can't think of any language that lets you omit the variable like that. What languages are you thinking of?

In Python, you could write:
Code:

`not (27 < month_num < 32)`
but then Python does not have do while loops.
• 08-09-2012
christop
Quote:

Originally Posted by laserlight
In Python, you could write:
Code:

`not (27 < month_num < 32)`
but then Python does not have do while loops.

I didn't know you could do that kind of test in Python (and it makes sense mathematically), but it's also a little different than the OP's problem. That expression will even compile in C, but won't give the same results (27 < month_num < 32 will always return 1, I think, because 0 and 1 (the two possible results from the subexpression 27 < month_num) is always less than 32).
• 08-09-2012
Korben
Quote:

Originally Posted by christop
I can't think of any language that lets you omit the variable like that. What languages are you thinking of?

I was thinking of PHP.
• 08-09-2012
laserlight
Quote:

Originally Posted by christop
I didn't know you could do that kind of test in Python (and it makes sense mathematically), but it's also a little different than the OP's problem.

It is similiar in that the test for a range between two values only involves one variable, syntactically.

Quote:

Originally Posted by christop
That expression will even compile in C, but won't give the same results (27 < month_num < 32 will always return 1, I think, because 0 and 1 (the two possible results from the subexpression 27 < month_num) is always less than 32).

It will compile in C if you #include <iso646.h>, but that's besides the point ;)

Quote:

Originally Posted by Korben
I was thinking of PHP.

To the best of my knowledge, PHP does not allow such syntax.
• 08-09-2012
Korben
You all are correct, I just tested it in PHP and I'm not sure what I was thinking. Guess it was a brain fart on my part lol.
• 08-09-2012
christop
Ah, yes, good old iso646.h. I don't think I've ever seen it used in the real world. Maybe I should start using it in my company's codebase to promote its use and increase awareness of it. :)

Fake edit: apparently Visual C++ 2005 doesn't support the is646.h macros without first including the header, even though C++ doesn't require the header. I'm not too surprised that Microsoft's compiler isn't close to standards-compliant. But that's getting a little bit too much off-topic.