Lvalue required as left operand of assignment

I got the error mentioned in the title on this line of code.
number%divisor=final;
In this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main (int argc, char * const argv[]) {
	int number=0, divisor=0, final;
	std::cout<<"Please enter a number\n";
	std::cin>>number;
	while (divisor<number){
		divisor=+1;
		number%divisor=final;
		if (final==0){
			std::cout<<divisor<<"\n";
		}
	}
	std::cout<<"done\n";
    return 0;
}

Ideas?
Last edited on
2 problems that I spot:

 
divisor=+1;


This is assigning divisor to 1. IE, it's the same as this:

 
divisor = +1;  // assign positive 1 to divisor 


If you want to increment divisor by one, you want to use +=:

 
divisor += 1;



Furthermore:

 
number%divisor=final;


you have this backwards. The variable being assigned needs to be on the left side of the = operator.

 
final = number % divisor;  // assigns the result of (number % divisor) to final 
Thanks it works perfectly. I can't believe I was stupid enough to make those mistakes, haha.
Topic archived. No new replies allowed.