non-lvalue in assignment?? WTF?

This is due in 50 minutes, so hopefully this gets a quick response. I'm getting an error that the internet isn't giving a clear response for.

First and foremost (even if I get my program working), for posterity sake will someone please explain what the error "NON-LVALUE IN ASSIGNMENT" actually means?

OK, now that being said my instructor has asked the class to take our program to determine prime numbers and modify it by including a function. For the prime number test. It worked fine before, so I'm not really interested in modifying the logic to "make more sense" (as I see this type of suggestion a lot on here) I'm sure there are a billion different ways to do this. I just need to know what is broke and why, if I can understand the error I can fix the error.

===> I'm getting the aforementioned error on line 50 (I bolded it). Here's what I got so far:


// Kyle ######
// Program #5
#include <iostream>
#include <cmath>
#include <iomanip>
#include <windows.h>
using namespace std;
// Super Awesome Cake Function of Awesomeness
void cake ()
{
cout << setfill ('-') << setw(76) << "-" << endl;
cout << " And Now For Cake ... " << endl;
Sleep(1500);
cout << " ... I promise it's not poisoned";
Sleep(1250);
cout << " ... beyond human tollerances" << endl;
Sleep(2000);
cout << endl << endl << "Humans like ethyl benzene, right?" << endl;
Sleep(1500);
cout << setfill ('-') << setw(76) << "-" << endl << endl << endl;
cout << " ,:/+/-" << endl;
cout << " /M/ .,-=;//;-" << endl;
cout << " .:/= ;MH/, ,=/+%$XH@MM#@:" << endl;
cout << " -$##@+$###@H@MMM#######H:. -/H#" << endl;
cout << " .,H@H@ X######@ -H#####@+- -+H###@x" << endl;
cout << " .,@##H; +XM##M/, =%@###@X;-" << endl;
cout << "X%- :M##########$. .:%M###@%:" << endl;
cout << "M##H, +H@@@$/-. ,;$M###@%, -" << endl;
cout << "M###M=,,---,.-%%H####M$: ,+@##" << endl;
cout << "@##################@/. :%##@$-" << endl;
cout << "M################H, ;HM##M$=" << endl;
cout << "##################. .=$M##M$=" << endl;
cout << "#################H..;XM##M$= .:+" << endl;
cout << "M####################@%= =+@MH%" << endl;
cout << "@#################M/. =+H#X%=" << endl;
cout << "=+M###############M, -/X#X+;." << endl;
cout << " .;XM###########H= ,/X#H+:," << endl;
cout << " .=+HM#######M+/+HM@+=." << endl;
cout << " ,:/%XM####H/." << endl;
cout << " ,.:=-." << endl << endl << endl;
}
// Prime Number Testing Function
void primetest (int num1, int num2, bool& notprime)
{
// Declare Local Variables for Function: primetest
int count = num2 - 1;
// Primetest Logic
while (count >= num1)
{
if (num2 % count = 0) // <==============THIS IS THE LINE THE ERROR IS HAPPENING ON
{
cout << count << " ";
notprime = true;
}
count--;
}
}
// **[BEGIN MAIN FUNCTION]**
int main()
{
// Declare Local Variables for Main
int num1,num2;
bool notprime = false;
// Main Logic
// Inital Data Input
cout << endl;
cout << " .,-:;//;:=," << endl;
Sleep (100);
cout << " . :H@@@MM@M#H/.,+%;," << endl;
Sleep (100);
cout << " ,/X+ +M@@M@MM%=,-%HMMM@X/," << endl;
Sleep (100);
cout << " -+@MM; $M@@MH+-,;XMMMM@MMMM@+-" << endl;
Sleep (100);
cout << " ;@M@@M- XM@X;. -+XXXXXHHH@M@M#@/." << endl;
Sleep (100);
cout << " ,%MM@@MH ,@%= .---=-=:=,." << endl;
Sleep (100);
cout << " =@#@@@MX., -%HX$$%%%:;" << endl;
Sleep (100);
cout << " =-./@M@M$ .;@MMMM@MM:" << endl;
Sleep (100);
cout << " X@/ -$MM/ . +MM@@@M$" << endl;
Sleep (100);
cout << ",@M@H: :@: . =X#@@@@-" << endl;
Sleep (100);
cout << ",@@@MMX, . /H- ;@M@M=" << endl;
Sleep (100);
cout << ".H@@@@M@+, %MM+..%#$." << endl;
Sleep (100);
cout << " /MMMM@MMH/. XM@MH; =;" << endl;
Sleep (100);
cout << " /%+%$XHH@$= , .H@@@@MX," << endl;
Sleep (100);
cout << " .=--------. -%H.,@@@@@MX," << endl;
Sleep (100);
cout << " .%MM@@@HHHXX$$$%+- .:$MMX =M@@MM%." << endl;
Sleep (100);
cout << " =XMMM@MM@MM#H;,-+HMM@M+ /MMMX=" << endl;
Sleep (100);
cout << " =%@M@M#@$-.=$@MM@@@M; %M%=" << endl;
Sleep (100);
cout << " ,:+$+-,/H#MMMMMMM@= =," << endl;
Sleep (100);
cout << " =++%%%%+/:-." << endl << endl << endl;
Sleep (100);
cout << " Welcome to Apeture Science's Prime Number Test v2" << endl << endl;
Sleep (100);
cout << " -----------------------------------------------------" << endl;
Sleep (100);
cout << " | Cake to be served @ the conclusion of the test |" << endl;
Sleep (100);
cout << " | Poison content of cake varies by particiapant |" << endl;
Sleep (100);
cout << " -----------------------------------------------------" << endl << endl << endl;
Sleep (100);
cout << "Enter an integer greater than 2 for the lower end of the range (ENTER 0 TO QUIT): ";
cin >> num1;
cout << endl << endl;

while (num1 != 0)
{
// Test for number being greater than 2
while (num1 <= 2)
{
cout << setfill ('X') << setw(76) << "X" << endl;
cout << setfill ('X') << setw(38) << " ERROR " << setfill ('X') << setw(38) << "X" << endl;
cout << " | " << setw(4) << setfill( ' ' ) << num1 << " is not greater than 2. Please re-enter an integer greater than 2. |" << endl;
cout << setfill ('X') << setw(76) << "X" << endl << endl << endl;
cout << "Enter an integer greater than 2 for the lower end of the range (ENTER 0 TO QUIT): ";
cin >> num1;
cout << endl << endl;
}
// Input Upper Range Number
cout << "Enter an integer greater than " << num1 << " for the upper end of the range: ";
cin >> num2;
cout << endl << endl;
// Test for number being greater than low end number
while (num2 <= num1)
{
cout << setfill ('X') << setw(76) << "X" << endl;
cout << setfill ('X') << setw(38) << " ERROR " << setfill ('X') << setw(38) << "X" << endl;
cout << " | " << setw(4) << setfill( ' ' ) << num2 << " is not greater than " << num1 <<". |" << endl;
cout << setfill ('X') << setw(76) << "X" << endl << endl << endl;
cout << "Enter an integer greater than " << num1 << " for the upper end of the range: ";
cin >> num2;
cout << endl << endl;
}
cout << "The Prime Numbers between " << num1 << " and " << num2 << " are:";
// Call to Function: primetest
primetest (num1, num2, notprime);
// Final Output
if (!notprime)
{
cout << "[There are no prime numbers in that range.]" << endl << endl << endl; // [PRIME RESPONSE]
}
// Quit?
cout << "Enter an integer greater than 2 for the lower end of the range (ENTER 0 TO QUIT): ";
cin >> num1;
}
cake ();
system("pause");
return 0;
}
I think that instead of

if (num2 % count = 0)

you meant

if (num2 % count == 0)

that is instead of assignment operator = you wanted to use equality operator ==

The error means that you cannot assign a value to an expression num2 % count
OK, that gets rid of the error (FINALLY! YEAH!!!)

... but apparently I suck at the math worse than I thought as the expected results of 10 for the lower range and 20 for the upper are 11 13 17 19, and I'm getting ... 10 ... *sigh*

OK well lets see what kind of bad math I implemented here.

Thanks for the info ... so if I see that error in the future it means I'm trying to assign a value to something that can't take that assignment?

lvalue is ... "literal value" or something like that?
closed account (zb0S216C)
An L-Value (Left-Value) is an operand* that can appear on both the left-hand & right-hand side of an assignment. L-Values generally have an address in memory, so the compiler knows where to store the value on the right-hand side.

An R-Value is also an operand that generally doesn't have an address in memory. These are usually magic constants or other objects, such as L-Values.

* An operand is a piece of data within an expression, such as an object, or magic constant (literal).

Wazzak
Last edited on
Topic archived. No new replies allowed.