Help with program ASAP!!!!!

Below is my code I need help adding the following features:

*Print the order summary, including the products, the quantities, and the total price for each product
*Calculate and print the total price for the order

I can really use help solving this. One of the requirements was to *Ask customers to select multiple products and quantities. It seems I got this figured out just need help with the last two features. Please help ASAP! real help not sending me a link to more confusion.



// Use of functions
#include <iostream>
#include <string>
using namespace std;


void displayMenu(string userName)
{

cout << userName << ", Please select the beverage you would like to purchase from the menu: " << endl;

cout << "Drink Menu" << endl;
cout << "========" << endl;
cout << "1 - Water $1" << endl;
cout << "2 - Soda $2" << endl;
cout << "3 - Iced Tea $3" << endl;
cout << "X - Exit " << endl << endl;
}

// View option 1 for <name>
void viewOption1(string name)
{
cout << "Name: " << name << endl;
cout << "Selection: " << "Water," << " Price: $1.45" << endl;
}


// View option 2 for <name>
void viewOption2(string name)
{
cout << "Name: " << name << endl;
cout << "Selection: " << "Soda," << " Price: $2.98" << endl;
}


// View option 3 for <name>
void viewOption3(string name)
{
cout << "Name: " << name << endl;
cout << "Selection: " << "Iced Tea," << " Price: $3.29" << endl;
}


int main(void)
{
char selection = ' ';
string name = "";
double price, subtl;
int code, quantity;
double total = 0; //allows you to use += to calculate produce subtotal since no tax.
//Will also reset total to 0 when you want to serve a new customer.

//Ask user for her/his name
cout << "Please enter your name ==> ";
getline(cin, name);

//display user name
cout << "Hello " + name << endl;

cout << "Would you like to see our drink menu: (Y/N)\n";
cin >> selection;

while (selection == 'y' || selection == 'Y')
{
displayMenu(name);

do
{
// display menu
//displayMenu(name);
cout << "Please select: ";
// read user selection
cin >> selection;


switch (selection)
{
case '1':
cout << "You selected Water" << endl;
cout << "Enter Quantity:";
cin >> quantity;
if (quantity <= 0)
{
cout << "Invalid Quantity" << endl;
cin >> quantity;
}
price = 1.45;
subtl = (quantity*price);
cout << "Subtotal $\n" << subtl << endl;
viewOption1(name);
break;
case '2':
cout << "You selected Soda" << endl;
cout << "Enter Quantity:";
cin >> quantity;
if (quantity <= 0)
{
cout << "Invalid Quantity" << endl;
cin >> quantity;
}
price = 2.98;
subtl = (quantity*price);
cout << "Subtotal $\n" << subtl << endl;
viewOption2(name);
break;
case '3':
cout << "You selected Iced Tea" << endl;
cout << "Enter Quantity:";
cin >> quantity;
if (quantity <= 0)
{
cout << "Invalid Quantity" << endl;
cin >> quantity;
}
price = 3.29;
subtl = (quantity*price);
cout << "Subtotal $\n" << subtl << endl;
viewOption3(name);
break;
cout << "Thank you!!!" << endl;
break;
case '0'://Sentinal value that gives subtotal (because no tax) then ends your function.
cout << "Subtotal: \n" << total << endl;
break;
// other than 1, 2, 3 and X...
default: cout << "Invalid selection. Please try again ";
// no break in the default case
}
total += subtl; //will add all the produce values up. is read as total=total+subt
} while (selection != 0);//checks if code = 0 at the end of function wont end till it is.
}
cout << "Would you like to continue shopping?(Y/N)";
cin >> selection;
}
I debugged what you have so far...

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140


// Use of functions
#include <iostream>
#include <string>
using namespace std;


void displayMenu(string userName)
{

	cout << userName << ", Please select the beverage you would like to purchase from the menu: " << endl;

	cout << "Drink Menu" << endl;
	cout << "========" << endl;
	cout << "1 - Water $1.45" << endl;
	cout << "2 - Soda $2.98" << endl;
	cout << "3 - Iced Tea $3.29" << endl;
	cout << "4 - Exit " << endl << endl; //use a number here or people may try x or X
}

// View option 1 for <name>
void viewOption1(string name)
{
	cout << "Name: " << name << endl;
	cout << "Selection: " << "Water," << " Price: $1.45" << endl;
}


// View option 2 for <name>
void viewOption2(string name)
{
	cout << "Name: " << name << endl;
	cout << "Selection: " << "Soda," << " Price: $2.98" << endl;
}


// View option 3 for <name>
void viewOption3(string name)
{
	cout << "Name: " << name << endl;
	cout << "Selection: " << "Iced Tea," << " Price: $3.29" << endl;
}


int main(void)
{
	char selection = ' ';
	string name = "";
	double price, subtl = 0; //need subtl initialized
	int code, quantity;
	double total = 0; //allows you to use += to calculate produce subtotal since no tax. 
					  //Will also reset total to 0 when you want to serve a new customer.

					  //Ask user for her/his name
	cout << "Please enter your name ==> ";
	getline(cin, name);

	//display user name
	cout << "Hello " + name << endl;

	cout << "Would you like to see our drink menu: (Y/N)\n";
	cin >> selection;

	while (selection == 'y' || selection == 'Y')
	{
		displayMenu(name);

		do
		{
			// display menu
			//displayMenu(name);
			cout << "Please select: ";
			// read user selection
			cin >> selection;


			switch (selection)
			{
			case '1':
				cout << "You selected Water" << endl;
				cout << "Enter Quantity:";
				cin >> quantity;
				if (quantity <= 0)
				{
					cout << "Invalid Quantity" << endl;
					cin >> quantity;
				}
				price = 1.45;
				subtl = (quantity*price);
				cout << "Subtotal $\n" << subtl << endl;
				viewOption1(name);
				break;
			case '2':
				cout << "You selected Soda" << endl;
				cout << "Enter Quantity:";
				cin >> quantity;
				if (quantity <= 0)
				{
					cout << "Invalid Quantity" << endl;
					cin >> quantity;
				}
				price = 2.98;
				subtl = (quantity*price);
				cout << "Subtotal $\n" << subtl << endl;
				viewOption2(name);
				break;
			case '3':
				cout << "You selected Iced Tea" << endl;
				cout << "Enter Quantity:";
				cin >> quantity;
				if (quantity <= 0)
				{
					cout << "Invalid Quantity" << endl;
					cin >> quantity;
				}
				price = 3.29;
				subtl = (quantity*price);
				cout << "Subtotal $\n" << subtl << endl;
				viewOption3(name);
				break;
				cout << "Thank you!!!" << endl;
				break;
			case '4'://Sentinal value that gives subtotal (because no tax) then ends your function.
				cout << "Subtotal: \n" << total << endl;
				selection = 0; //to end the menu
				break;
				// other than 1, 2, 3 and X...
			default: cout << "Invalid selection. Please try again ";
				// no break in the default case
			}
			total += subtl; //will add all the produce values up. is read as total=total+subt
		} while (selection != 0);//checks if code = 0 at the end of function wont end till it is.
	}
	cout << "Would you like to continue shopping?(Y/N)";
	cin >> selection;

	return 0; //end the program
}


Next you should write a new function that prints out the customers total order and price.
Or you can just add something like this to the end of the program...

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Use of functions
#include <iostream>
#include <string>
using namespace std;


void displayMenu(string userName)
{

	cout << userName << ", Please select the beverage you would like to purchase from the menu: " << endl;

	cout << "Drink Menu" << endl;
	cout << "========" << endl;
	cout << "1 - Water $1.45" << endl;
	cout << "2 - Soda $2.98" << endl;
	cout << "3 - Iced Tea $3.29" << endl;
	cout << "4 - Exit " << endl << endl; //use a number here or people may try x or X
}

// View option 1 for <name>
void viewOption1(string name)
{
	cout << "Name: " << name << endl;
	cout << "Selection: " << "Water," << " Price: $1.45" << endl;
}


// View option 2 for <name>
void viewOption2(string name)
{
	cout << "Name: " << name << endl;
	cout << "Selection: " << "Soda," << " Price: $2.98" << endl;
}


// View option 3 for <name>
void viewOption3(string name)
{
	cout << "Name: " << name << endl;
	cout << "Selection: " << "Iced Tea," << " Price: $3.29" << endl;
}


int main(void)
{
	char selection = ' ';
	string name = "";
	double price, subtl = 0; //need subtl initialized
	int code, quantity;
	double total = 0; //allows you to use += to calculate produce subtotal since no tax. 
					  //Will also reset total to 0 when you want to serve a new customer.

					  //Ask user for her/his name
	cout << "Please enter your name ==> ";
	getline(cin, name);

	//display user name
	cout << "Hello " + name << endl;

	cout << "Would you like to see our drink menu: (Y/N)\n";
	cin >> selection;

	while (selection == 'y' || selection == 'Y')
	{
		displayMenu(name);

		do
		{
			// display menu
			//displayMenu(name);
			cout << "Please select: ";
			// read user selection
			cin >> selection;


			switch (selection)
			{
			case '1':
				cout << "You selected Water" << endl;
				cout << "Enter Quantity:";
				cin >> quantity;
				if (quantity <= 0)
				{
					cout << "Invalid Quantity" << endl;
					cin >> quantity;
				}
				price = 1.45;
				subtl = (quantity*price);
				cout << "Subtotal $\n" << subtl << endl;
				viewOption1(name);
				break;
			case '2':
				cout << "You selected Soda" << endl;
				cout << "Enter Quantity:";
				cin >> quantity;
				if (quantity <= 0)
				{
					cout << "Invalid Quantity" << endl;
					cin >> quantity;
				}
				price = 2.98;
				subtl = (quantity*price);
				cout << "Subtotal $\n" << subtl << endl;
				viewOption2(name);
				break;
			case '3':
				cout << "You selected Iced Tea" << endl;
				cout << "Enter Quantity:";
				cin >> quantity;
				if (quantity <= 0)
				{
					cout << "Invalid Quantity" << endl;
					cin >> quantity;
				}
				price = 3.29;
				subtl = (quantity*price);
				cout << "Subtotal $\n" << subtl << endl;
				viewOption3(name);
				break;
				cout << "Thank you!!!" << endl;
				break;
			case '4'://Sentinal value that gives subtotal (because no tax) then ends your function.
				cout << "Subtotal: \n" << total << endl;
				selection = 0; //to end the menu
				break;
				// other than 1, 2, 3 and X...
			default: cout << "Invalid selection. Please try again ";
				// no break in the default case
			}
			total += subtl; //will add all the produce values up. is read as total=total+subt
		} while (selection != 0);//checks if code = 0 at the end of function wont end till it is.
	}
	cout << "Would you like to continue shopping?(Y/N)";
	cin >> selection;

	if (subtl > 0) {
		cout << endl << endl;
		cout << "Your subtotal is: $" << subtl << endl;
		total = subtl + (subtl * .08);
		total *= 100;
		total = round(total);
		total /= 100;
		cout << "Your total with tax is: $" << total << endl;
		//cout << total;
	}

	cin.ignore();
	cin.get();
	return 0; //end the program
}
Last edited on
Topic archived. No new replies allowed.