Error message 'non-lvalue in assignment', any suggestions?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • millman
    New Member
    • Oct 2011
    • 5

    Error message 'non-lvalue in assignment', any suggestions?

    Code:
    #pragma hdrstop
    #include <conio.h>
    #include <ctype.h>
    #include <iostream>
    
    #pragma argsused
    
    //-------------------------------------------------------
    
    using namespace std;
    int main ( ) { 
    int i;
    int x;
    std::cout << "\nPlease enter an even number:";
    cin >> x;
    if(x%2=1)
             std::cout << "\nNumber entered was not even.";
    else
        std::cout << "\nNimber entered was " <<x<< ".";
        std::cout << "\n\nNext ten even values: ";
    for (i=0; i<=8; i++) 
    {
    	 x=x+2;
         std::cout <<x<< " "; 
    }
    x=x+2;
    std::cout <<x<< ".";
    getch();
    return 0;
    }
    This my code and the problem is with the if statement. That's when the error message appears :(
  • millman
    New Member
    • Oct 2011
    • 5

    #2
    Don't worry, i worked it out myself but just incase anyone else has a similar problem you need two equals signs like this == in the if statement. Also if you use windows visual c++ you need this header file. #include <StdAfx.h>

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You only need <stdafx.h> is you have a Win32 application as opposed to a Win32 Console Application project where you have created as empty and not using precompiled headers.

      Comment

      Working...