# Non-lvalue in Program Question

• 11-07-2008
thekautz
Non-lvalue in Program Question
Hello,
The errors are at the bottom of the post, and they are about the error: non-lvalue.
I am writing a program which allows the user to choose a beverage, sandwich and side order from a menu. After the choices are made, the program should do the following:

* list the items chosen with the cost of each item
* the sub-total of just the items
* the total cost including tax (use 6.5% for the tax).

The following are the items and prices I will include:

Beverages:
1: Soda: \$0.99
2: Milk: \$0.79
3: Juice: \$1.29

Sandwiches:
1: Hamburger: \$0.99
2: Cheeseburger: \$1.09
3: Chicken Sandwich: \$2.59

Side Orders:
1: French Fries: \$0.89
2: Onion Rings: \$1.09
3: Corn Chips: \$0.59

The output should look something like this (it must include the items and prices, the sub-total, the tax, and the total cost including tax)

Soda: \$0.99
Hamburger: \$0.99
French Fries: \$0.89

Total of food: \$2.87
Tax: \$0.19
Total for order: \$3.06

Code:

```#include <iostream> #include <string> int main () { int drink; int sandwich; int side; double price; double soda; double milk; double juice; double hamburger; double cheeseburger; double chicken; double fries; double rings; double chips; soda = .99; milk = .79; juice = 1.29; hamburger = .99; cheeseburger = 1.09; chicken = 2.59; fries = .89; rings = 1.09; chips = .59; cout << "Pick Drink & input coresponding number" << endl; cout << "1: Soda \$0.99" << endl; cout << "2: Milk \$0.79" << endl; cout << "3: Juice \$1.29" << endl; cin >> drink;         if (drink == 1)         {price + soda = price;}         if (drink == 2)         {price + milk = price;}         if (drink == 3)         {price + juice = price;} cout << "Pick Sandwich & input coresponding number" << endl; cout << "1: hamburger \$0.99" << endl; cout << "2: cheeseburger \$1.09" << endl; cout << "3: chicken \$2.59" << endl; cin >> sandwich;         if (sandwich == 1)         {price + hamburger = price;}         if (sandwich == 2)         {price + cheeseburger = price;}         if (sandwich == 3)         {price + chicken = price;} cout << "Pick Side & input coresponding number" << endl; cout << "1: fries \$0.89" << endl; cout << "2: onion rings \$1.09" << endl; cout << "3: corn chips \$0.59" << endl; cin >> side;         if (side == 1)         {price + fries = price;}         if (side == 2)         {price + rings = price;}         if (side == 3)         {price + chips = price;} if (drink == 1) cout << "Soda: \$0.99" << endl; if (drink == 2) cout << "Milk: \$0.79" << endl; if (drink == 3) cout << "Juice: \$1.29" << endl; if (sandwich == 1) cout << "Hamburger: \$0.99" << endl; if (sandwich == 2) cout << "Cheeseburger: \$1.09" << endl; if (sandwich == 3) cout << "Chicken: \$2.59" << endl; if (side == 1) cout << "Fries: \$0.89" << endl; if (drink == 2) cout << "Onion Rings: \$1.09" << endl; if (drink == 3) cout << "Chips: \$0.59" << endl; cout << "Price: " << price << endl; cout << "Tax: " << price * .065 << endl; cout << "Total: " << price * 1.065 << endl; return 0; }```
That is what I have.
Here are the errors that display:
Code:

```menu.cpp: In function `int main()': menu.cpp:33: non-lvalue in assignment menu.cpp:35: non-lvalue in assignment menu.cpp:37: non-lvalue in assignment menu.cpp:45: non-lvalue in assignment menu.cpp:47: non-lvalue in assignment menu.cpp:49: non-lvalue in assignment menu.cpp:57: non-lvalue in assignment menu.cpp:59: non-lvalue in assignment menu.cpp:61: non-lvalue in assignment```
I do not know what non-lvalue means, so it would be great if someone could help me out there, it would be greatly appreciated!
Thank you!
• 11-07-2008
nucleon
This (and all like it) is backwards:
Code:

`price + soda = price;`
Should be
Code:

`price = price + soda;`
or
Code:

`price += soda;`
An l-value (left value) is something that can be assigned to.
• 11-07-2008
thekautz
Yes!
I remember that now.
Now it is working!
Thank you nucleon!