Like Tree2Likes
  • 1 Post By std10093
  • 1 Post By oogabooga

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

This is a discussion on HELP: "expected expression before '>=' token" error, cant figure out whats wrong??? within the C Programming forums, part of the General Programming Boards category; I've been fixing bugs and errors for hours and now have a raging migraine. I finally got my script from ...

  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:
    Name:  zNm3.jpeg
Views: 228
Size:  30.3 KB

    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)
    laserlight likes this.

  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);
    laserlight likes this.
    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

    Name:  zSfp.jpeg
Views: 264
Size:  111.3 KB

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    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
    22,303
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    383
    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
    22,303
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    383
    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, 05:23 PM
  2. Replies: 7
    Last Post: 09-14-2008, 09:37 AM
  3. expected primary expression before "." token
    By melodious in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 05:39 AM
  4. Replies: 24
    Last Post: 09-06-2006, 07:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21