What is wrong with my C++ program?

This is my assignment:

Write a menu-driven program that will allow the user to select 1 item from Chuckie's Kitchen Hot Sandwiches, 1 additional side order item, and 1 beverage. The program should compute the total and print the amount of the user's total bill (formatted to two decimal points). Implement your menu logic using either if /else if blocks or a switch blocks.

This is the menu:
http://i231.photobucket.com/albums/ee256/skymack123/chuckies_kitchen_menu.jpg


Here's my program, can you tell me how to fix it please?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int MAIN_DISH = 8 pcs wings, 10 pcs wings, 12 pcs wings, 15 pcs wings, 20 pcs wings, chili dog, fish fry, chicken breast, bbq rib boneless, bacon burger, cheeseburger, turkey burger, double burger, turkey, roast beef, ham & cheese, tuna, deluxe mix

const int SIDE_ORDER = french fries, onion rings, macaroni & cheese, cole slaw

const int BEVERAGE = pepsi, orange, mountain dew, root beer, water, sierra mist, orange juice, apple juice


8 pcs wings = 4.50
10 pcs wings = 5.00
12 pcs wings = 5.70
15 pcs wings = 6.70
20 pcs wings = 8.75
chili dog = 2.50
fish fry = 4.95
chicken breast = 4.95
bbq rib = 5.95
bacon burger = 4.95
cheeseburger = 3.95
turkey burger = 3.95
double burger = 5.95
turkey = 2.50
roast beef = 4.95
ham & cheese = 4.95
tuna = 3.95
deulxe mix = 4.95

french fries = 2.50
onion rings = 2.75
macaroni & cheese = 2.50
cole slaw = 2.25

pepsi = 1.25
orange = 1.25
mountain dew = 1.25
root beer = 1.25
water = 1.00
sierra mist = 1.25
orange juice = 1.50
apple juice = 1.50




cout << "Enter an item: ";
cin >> MAIN_DISH;

cout << "Enter a side order: ";
cin >> SIDE_ORDER;

cout << "Enter a beverage: ";
cin >> BEVERAGE;


cin >> MAIN_DISH + SIDE_ORDER + BEVERAGE;

return ("pause");


Variable names cannot start with a number and cannot contain spaces. double is a keyword. int's cannot be initialized with a decimal value.
Fix those first.
Like this?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int MAIN_DISH = eight_pcs_wings, ten_pcs_wings, twelve_pcs_wings, fifteen_pcs_wings, twenty_pcs_wings, chili_dog, fish_fry, chicken_breast, bbq_rib, bacon_burger, cheeseburger, turkey_burger, double-burger, turkey, roast_beef, ham_&_cheese, tuna, deluxe_mix

const int SIDE_ORDER = french fries, onion rings, macaroni & cheese, cole slaw

const int BEVERAGE = pepsi, orange, mountain dew, root beer, water, sierra mist, orange juice, apple juice


8 pcs wings = 4.50
10 pcs wings = 5.00
12 pcs wings = 5.70
15 pcs wings = 6.70
20 pcs wings = 8.75
chili dog = 2.50
fish fry = 4.95
chicken breast = 4.95
bbq rib = 5.95
bacon burger = 4.95
cheeseburger = 3.95
turkey burger = 3.95
double-burger = 5.95
turkey = 2.50
roast beef = 4.95
ham & cheese = 4.95
tuna = 3.95
deulxe mix = 4.95

french fries = 2.50
onion rings = 2.75
macaroni & cheese = 2.50
cole slaw = 2.25

pepsi = 1.25
orange = 1.25
mountain dew = 1.25
root beer = 1.25
water = 1.00
sierra mist = 1.25
orange juice = 1.50
apple juice = 1.50




cout << "Enter an item: ";
cin >> MAIN_DISH;

cout << "Enter a side order: ";
cin >> SIDE_ORDER;

cout << "Enter a beverage: ";
cin >> BEVERAGE;


cin >> MAIN_DISH + SIDE_ORDER + BEVERAGE;

return ("pause");
How do I write "Double Burger" without using the keyword?
You missed these.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
8 pcs wings = 4.50
10 pcs wings = 5.00
12 pcs wings = 5.70
15 pcs wings = 6.70
20 pcs wings = 8.75
chili dog = 2.50
fish fry = 4.95
chicken breast = 4.95
bbq rib = 5.95
bacon burger = 4.95
cheeseburger = 3.95
turkey burger = 3.95
double-burger = 5.95
turkey = 2.50
roast beef = 4.95
ham & cheese = 4.95
tuna = 3.95
deulxe mix = 4.95

french fries = 2.50
onion rings = 2.75
macaroni & cheese = 2.50
cole slaw = 2.25

pepsi = 1.25
orange = 1.25
mountain dew = 1.25
root beer = 1.25
water = 1.00
sierra mist = 1.25
orange juice = 1.50
apple juice = 1.50


For the double..
 
double_burger = 5.95
Thanks, I realized I missed them after I posted it.
Okay, now I've fixed those things. What else?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int MAIN_DISH = eight_pcs_wings, ten_pcs_wings, twelve_pcs_wings, fifteen_pcs_wings, twenty_pcs_wings, chili_dog, fish_fry, chicken_breast, bbq_rib, bacon_burger, cheeseburger, turkey_burger, double_burger, turkey, roast_beef, ham_&_cheese, tuna, deluxe_mix

const int SIDE_ORDER = french fries, onion rings, macaroni & cheese, cole slaw

const int BEVERAGE = pepsi, orange, mountain dew, root beer, water, sierra mist, orange juice, apple juice


eight pcs wings = 4.50
ten pcs wings = 5.00
twelve pcs wings = 5.70
fifteen pcs wings = 6.70
twenty pcs wings = 8.75
chili dog = 2.50
fish fry = 4.95
chicken breast = 4.95
bbq rib = 5.95
bacon burger = 4.95
cheeseburger = 3.95
turkey burger = 3.95
double_burger = 5.95
turkey = 2.50
roast beef = 4.95
ham & cheese = 4.95
tuna = 3.95
deulxe mix = 4.95

french fries = 2.50
onion rings = 2.75
macaroni & cheese = 2.50
cole slaw = 2.25

pepsi = 1.25
orange = 1.25
mountain dew = 1.25
root beer = 1.25
water = 1.00
sierra mist = 1.25
orange juice = 1.50
apple juice = 1.50




cout << "Enter an item: ";
cin >> MAIN_DISH;

cout << "Enter a side order: ";
cin >> SIDE_ORDER;

cout << "Enter a beverage: ";
cin >> BEVERAGE;


cin >> MAIN_DISH + SIDE_ORDER + BEVERAGE;

return ("pause");
wow, there's so much syntax errors. you should learn tutorial from this site...
How can I fix it? I think the problems are with how I'm listing the items on the menu.
There's a lot of things going wrong. You should learn some more of the language and programming.

An int cannot be with a decimal point.
Variable names cannot contain spaces (use underscores _ ).

You also probably need a some container (In Java it's a HashMap, not shure what it's called in C++) that associates strings to numbers, because an input string (what you're getting from cin) cannot be directly used to access variables (whose names, as far as I know, are modified during compilation anyway).

You also forgot the must-have semicolon ( ; ) after your variable declarations.

Also, an int can only contain an integer number, so no decimals or "pepsi, orange, mountain dew, root beer, water, sierra mist, orange juice, apple juice"

Last edited on
closed account (zb0S216C)
Variable identifiers must follow these rules:

1) Identifiers cannot begin with a number.
2) Identifiers cannot contain spaces. However, they can contain underscores.
3) Identifiers cannot equal to reserved words.
4) Identifiers are case sensitive.
5) Identifiers cannot contain these: ! " £ % ^ & * ( ) - + [ ] { } ' @ ~ # : ; ? / . > , < | \ ` ¬. Only Aa to zZ.

Skyza wrote:
cin >> MAIN_DISH + SIDE_ORDER + BEVERAGE;

No. Replace + with >>.

Skyza wrote:
return ("pause");
return(0) or return 0.

Wazzak
Last edited on
First, as everyone has already stated, you need to fix your variables and declarations. You can read about them here:

http://www.cplusplus.com/doc/tutorial/variables/

You also didn't follow the directions to the actual assignment -- it states you need to print the total amount of the bill (no where in your program did you cout anything stating the user's total) and to implement either if/else or switch statements. I'd suggest reading up on these since I'm assuming you don't know much about them:

http://www.cplusplus.com/doc/tutorial/control/

Line 7 is certainly longer than 80 characters, and it's good programming practice (and I believe prevents compiler errors) to keep it <= 80 characters.

I highly suggest using a switch statement for this project, it's a bit advanced but more practical than writing an if/else. I had an assignment just like this in my beginner programming class and I used switches. Good luck.
Last edited on
Also, the assignment as you posted it asks for a user to pick one hot sandwich.

So, this

const int MAIN_DISH = eight_pcs_wings, ten_pcs_wings, twelve_pcs_wings, fifteen_pcs_wings, twenty_pcs_wings, chili_dog, fish_fry, chicken_breast, bbq_rib, bacon_burger, cheeseburger, turkey_burger, double_burger, turkey, roast_beef, ham_&_cheese, tuna, deluxe_mix

can be shortened to this

 
const int chili_dog, fish_fry, chicken_breast, bbq_rib, bacon_burger, cheeseburger, turkey_burger, double_burger;


if you want to have values for these variables which are not integers, then you need to declare them as another type.

for example.

1
2
3
4
5
6
7
8
9
const float  chili_dog, fish_fry, chicken_breast, bbq_rib, bacon_burger, cheeseburger, turkey_burger, double_burger;

float hot_sandwich;
float side_order;
float drink;

chili_dog=2.5;
...


You might also want to associate a number with your items.

[1] chili dog
[2] fish fry

And then you can ask the user to pick an item like this.
1
2
3
4
5
6
7
8
int choice;

cout << "Pick a hot sandwich. " << //list the hot sandwich options
cin >> choice;

if (choice == 1) hot_sandwich=chili_dog;
else if (choice==2) hot_sandwich=fish_fry;
Maybe you want to try it like this:

string main;
string side;
string bev;
double price = 0;
int position = 0;

map<string, double> main_dish;
main_dish["8 pcs wings"] = 4.50;
main_dish["10 pcs wings"] = 5.00;

map<string, double> side_order;
side_order["french fries"] = 2.50;

map<string, double> beverage;
beverage["pepsi"] = 1.25;

cout << "Enter an item: ";
getline(cin, main);

cout << "Enter a side order: ";
getline(cin, side);

cout << "Enter a beverage: ";
getline(cin, bev);

price = main_dish.find(main)->second;
price += side_order.find(side)->second;
price += beverage.find(bev)->second;

cout << "The price is " << 	price << endl;
Topic archived. No new replies allowed.