I always get the error ((IntelliSense: expression must be a modifiable lvalue )) for the expression used with the "for" , please help .
for (c=2 ; c <= x -1 ; c++ )
if ( x % c = 0 )
cout << "not prime" ;
else cout << "prime";
I always get the error ((IntelliSense: expression must be a modifiable lvalue )) for the expression used with the "for" , please help .
for (c=2 ; c <= x -1 ; c++ )
if ( x % c = 0 )
cout << "not prime" ;
else cout << "prime";
I guess you're trying to compare the result of x % c with 0. In this case,
if ( x % c = 0 )
This must be
// --------v
if ( x % c == 0 )
Note the additional =.
The reason is, that x % c does not return modifiable lvalue and using only one =, you're trying to assing 0 to the result of x % c, which is wrong.
As far as I can tell you probably meant == instead of = here:
if ( x % c = 0 )
so like this:
if ( x % c == 0 )
In the first case you are trying to assign to result of an % operation which is a temporary and can not be assigned to. This previous thread covers some of the issues around temporaries. This article is a little more in depth but will probably give you a better understanding Understanding lvalues and rvalues in C and C++.
You're missing an = in the if line:
for (c=2 ; c <= x -1 ; c++ )
if ( x % c == 0 )
cout << "not prime" ;
else cout << "prime";
(not that your code will tell you if a number is prime; it will print whether it's a multiple of every number smaller than it)
You're missing a =:
if ( x % c == 0 )
^^----
= is an assignment, == is an equality test.
I guess, you should look again at x % c == 0. You're assigning zero to the result of x modulo c.
For me your code works well as follows (Objective-C, so there's no @cout@, we use @NSLog();@:
for ( c = 2; c <= x-1; c++ )
if ( x % c == 0 ) NSLog(@"not prime");
else NSLog(@"prime");