what is wrong with line 27 and 31?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joeyke
    New Member
    • Feb 2010
    • 15

    what is wrong with line 27 and 31?

    this was my task: Ask the user to enter a number, and then read in the number from the keyboard. Print out the number and also output whether the number is positive, negative or zero, and also output whether the number is even or odd.
    look at my program attached to this post. thanks!
    }
    for (numb1=numb1+0; numb1%2=0;) //line27 error:invalid lvalue in assignment
    {
    cout<<" and is positive";
    }
    for (numb1=numb1+0; numb1%2><0;) //line31 error: expected primary-expression before '<' token
    {
    cout<<" and is negative ";
    }
    Attached Files
  • grayMist
    New Member
    • Feb 2010
    • 12

    #2
    joeyke please put your code snippets inside code tags,
    that make the code a lot easier to read.

    Line 27:
    numb1%2=0 ; here numb1%2 is an expression, so it can not be a lvalue.
    If you are trying to compare numb1%2 with 0 , use double equal-to signs ,
    ie. '=='


    Line 31:
    numb1%2><0 is not a valid c/c++ syntax.
    I'm assuming you are attempting to check numb1%2 is not equal to 0 ,
    use the ' != ' operator instead.

    Comment

    • joeyke
      New Member
      • Feb 2010
      • 15

      #3
      hey

      thanks for your help ! i made the changes you suggested and they worked but i get an endless sentence repeated many times in my output. how can i just get it to print out one sentence?

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        Because you don't do anything in the loop body or in the loop increment expression that affects condition. Once it's true, it executes forever.

        Comment

        Working...