Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have written a c++ code to solve a problem and getting compilation error for the
13 and 15 line
"1value required as left operand of assignment "

What I have tried:

C++
int k;
int x;
int y;

bool prime_number(int z);
void devisible()
{
    for(int i=2;i<k;i++)>
    {
        if(k%i==0)
        {  prime_number(k)=false;// this is line 13
         break;  }
         else
            prime_number(k)=true;// this is line 15
}
}
int next_prime_number()
{
    for(int k; ; k++)
    {
        if(prime_number(k))
            return k;
        break;
    }

}
Posted
Updated 22-Jun-16 20:18pm
v2

C#
bool prime_number(int z);

is a function that return a boolean, and in your code you want to set true/false to that function ?
C#
prime_number(k)=false;

that is not possible.
 
Share this answer
 
 
Share this answer
 
It's not "1value", it's "l-value", where 'l' means "left". This is explained, for example, here: Lvalues and Rvalues (Visual C++).

Doesn't it make sense? :-)

—SA
 
Share this answer
 
You are using the 'prime_number' like a variable, but it is a function.

C++
 int next_prime_number()
{
    for(int k; ; k++)
    {
        if(prime_number(k)) // This is how it should be used.
            return k;
        break;
    }
 
}


Looking at the code, the function devisible() should be renamed to 'prime_number(int z)',
because the function checks if a given number is prime or not.
 
Share this answer
 
In C-family languages, you denote arrays with brackets [], not with parenthesis ().
 
Share this answer
 
You must use == for equal-compare operations
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900