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

  1. #1
    Registered User Korben's Avatar
    Join Date
    Aug 2012
    Location
    Seattle, WA
    Posts
    7

    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:
    HELP: "expected expression before '>=' token" error, cant figure out whats wrong???-znm3-jpeg

    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:
    1. #include <stdio.h>
    2. #include <cs50.h>
    3. int main(void) {
    4. int MonthNum;
    5. long long Pennies;
    6. /* ask user for total days in the month */
    7. do {
    8. printf("Enter total days in the month: \n");
    9. MonthNum = GetInt();
    10. }
    11. while (MonthNum <= 27 || >= 32);
    12. /* ask user for starting amount of pennies */
    13. do {
    14. printf("Starting number of pennies on Day 1: \n");
    15. Pennies = GetInt();
    16. }
    17. while( Pennies <1 );
    18. /* calculate total pennies earned over a month */
    19. for(int i = 0; i < MonthNum-1; i++) {
    20. Pennies = Pennies * 2;
    21. }
    22. /* turn total pennies into dollars */
    23. Pennies = Pennies / 100;
    24. /* display money to screen */
    25. printf("You made a total of $%lld \n", Pennies);
    26. return 0;
    27. }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    line 11 should be
    Code:
    while(MonthNum<=27 || MonthNum>=32)

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    This
    Code:
    while (MonthNum <= 27 || >= 32);
    needs to be this
    Code:
    while (MonthNum <= 27 || MonthNum >= 32);
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #4
    Registered User Korben's Avatar
    Join Date
    Aug 2012
    Location
    Seattle, WA
    Posts
    7
    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

    HELP: &quot;expected expression before '&gt;=' token&quot; error, cant figure out whats wrong???-zsfp-jpeg

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    I can't think of any language that lets you omit the variable like that. What languages are you thinking of?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    Quote Originally Posted by laserlight View Post
    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).

  8. #8
    Registered User Korben's Avatar
    Join Date
    Aug 2012
    Location
    Seattle, WA
    Posts
    7
    Quote Originally Posted by christop View Post
    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.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User Korben's Avatar
    Join Date
    Aug 2012
    Location
    Seattle, WA
    Posts
    7
    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.

  11. #11
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  2. Replies: 7
    Last Post: 09-14-2008, 08:37 AM
  3. expected primary expression before "." token
    By melodious in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 04:39 AM
  4. Replies: 24
    Last Post: 09-06-2006, 06:17 PM