Zombie Sandwich Shop Program

closed account (oG8qGNh0)
Zombie Sandwich Shop

The BRAINS! Vision
BRAINS! caters to a clientele that is extremely specific in their needs, demanding in their requirements, and hungry for BRAINS.

Your Task
Help the staff of BRAINS! provide speedier service by creating a cash register (point-of-sale) system that allows the cashier to quickly select items off the menu as they are SHRIEKED by the customer and quickly totals those items, applies sales tax, and reveals the total.

Items on the Menu
Thala Mustard-Crusted Filet - $17.50
Hypotha Moussaka - $12.95
Amyg-DAL-a - $11.56
HIPpocampus & Dip- $7.99
Pons Pasta Special - $15.00
Medulla Frittata - $9.99
Finish Current Sale + Start a New Sale
Quit Forever - APOCALYPSE

What Else You Need to Know
Maryland sales tax is 6% (even for zombies).

Your program should offer the items as a menu that makes it clear what the cashier should press to indicate that item.

The program should run until they choose the option to just GIVE UP ENTIRELY (8) (close out the system completely) because the apocalypse is at hand! Up until that point, the cashier should be allowed to continue to add items to the order, one item at a time. The total should accumulate as the program runs.

If the cashier enters a non-menu option (malicious input - like -10 or 255), the program should urge them to HURRY! And display the menu again.

Once the cashier selects the option to total the sale, sales tax should be calculated and displayed, and the total before and after tax should be displayed. Ensure that it looks like MONEY (2 decimal places).
Once the total has been displayed, output a few blank lines on screen. The total for the previous sale should be cleared (back to 0), and the menu of options displayed again. If they choose the final option labeled apocalypse, end the program completely (break the loop).

Make sure to include labels with any output to explain what numbers represent.

Output a few blank lines and redisplay the menu each time a new input is entered.

My code so far; no need to do it for me duh!

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
#include <iostream>

using namespace std;

int main() {

constexpr auto filet {17.50};

// Thala Mustard-Crusted Filet

constexpr auto moussaka {12.95};

// Hypotha Moussaka

constexpr auto amyg {11.56};

// Amyg-DAL-a

constexpr auto dip {7.99};

// HIPpocampus & Dip

constexpr auto pasta {15.00};

// Pons Pasta Special

constexpr auto frittata {9.99};

// Medulla Frittata

constexpr auto {};

//

constexpr auto {};

//

}


Im not sure what to add in the last constexpr autos.
Last edited on
I don't see any need for them. Remove them.
What's your level of C++ knowledge - as I'd be considering holding the menu (text to display and the item price) as an array with the cashier told to enter the item number for the selected item.

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
#include <iostream>
#include <iterator>
#include <limits>

int main()
{
	struct item {
		const char* const desc;
		double price;
	};

	constexpr item menitms[] {{"Thala Mustard-Crusted Filet", 17.50},
				{"Hypotha Moussaka", 12.95},
				{"Amyg-DAL-a", 11.56},
				{"Hippocampus & Dip", 7.99},
				{"Pons Pasta Special", 15},
				{"Medulla Frittata", 9.99}};

	int opt {};

	do {
		// Display menu
		std::cout << "\n\nZombie Sandwich Shop\n\n";

		for (size_t i = 0; i < std::size(menitms); ++i)
			std::cout << i << ")  " << menitms[i].desc << "  " << menitms[i].price << '\n';

		std::cout << std::size(menitms) << ")  Give up entirely\n";

		// Get option
		while (((std::cout << "\nEnter item number: ") && !(std::cin >> opt)) || (opt < 0 || opt > std::size(menitms))) {
			std::cout << "Invalid menu options\n";
			std::cin.clear();
			std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
		}

		// If not quit option display and process
		if (opt != std::size(menitms)) {
			std::cout << "\nYou chose option " << menitms[opt].desc << " for " << menitms[opt].price << '\n';

			// Process option here
		}

	// Loop until quit option
	} while (opt != std::size(menitms));
}

Last edited on
closed account (oG8qGNh0)
Python Knowledge - 100%
Java Knowledge - 85%
C Knowledge - 0%
C++ Knowledge - 2%
closed account (oG8qGNh0)
e
Last edited on
closed account (oG8qGNh0)
Why do you need

#include <iterator>
#include <limits>
<limits> contains std::numeric_limits
https://en.cppreference.com/w/cpp/types/numeric_limits

<iterator> contains std::size (although a number of other headers are also guaranteed to contain std::size)
https://en.cppreference.com/w/cpp/iterator/size

(I don't condone the use of that weird while loop condition; it also generates a warning in GCC. Split it up into multiple statements or factor it out into a function.)
Last edited on
closed account (oG8qGNh0)
((std::cout << "\nEnter item number: ") && !(std::cin >> opt) ||


Half of Line 31 is red underlined
ok. You should post the actual compiler messages in the future.

Split it up into something saner if you don't like it.
Move the actual statements like the cout and the condition checking into the while loop, and have the condition be:
1
2
3
4
5
// ask user for input
while (opt < 0 || opt >= std::size(menitms))
{
    // ask user for input
}


or
1
2
3
4
5
do
{
    // ask user for input
}
while (opt < 0 || opt >= std::size(menuitms));


(If your compiler isn't new enough for std::size, you can just hardcode a 6 there)
Last edited on
I forgot you're using repl.it which uses clang..... It underlines line 31 in green as a warning because it doesn't trust the code and is trying to save the coder from themselves. The code is correct as && has a higher precedence than || so is evaluated first. If both parts of the && are true, the rest is not evaluated. If the cin fails then cin returns 'false' which is negated to true. So the || statements are only evaluated if both the output and input were done without error.

The statement is equivalent to:

 
while (((std::cout << "\nEnter item number: ") && !(std::cin >> opt)) || (opt < 0 || opt > std::size(menitms))) {


which removes the clang warning.

See https://repl.it/repls/TenderTerrificCgi#main.cpp

closed account (oG8qGNh0)
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
/*

Zombie Sandwich Program by Naveen Menon

*/

#include <iostream>
#include <iostream>
#include <iterator>

int main()

{
struct item {
const char * const desc;
double price;
};

constexpr item menitms[] 

//menitms = menuitems

{{"Thala Mustard-Crusted Filet", 17.50},

{"Hypotha Moussaka", 12.95},

{"Amyg-DAL-a", 11.56},

{"Hippocampus & Dip", 7.99},

{"Pons Pasta Special", 15},

{"Medulla Frittata", 9.99}};

int opt {};

do {

// Display menu

std::cout << "\n\nZombie Sandwich Shop\n\n";

for (size_t i = 0; i < std::size(menitms); ++i)

std::cout << i << ")  " << menitms[i].desc << "  " << menitms[i].price << '\n';

std::cout << std::size(menitms) << ")  Give up entirely\n";

// Get option

while (((std::cout << "\nEnter item number: ") && !(std::cin >> opt)) || (opt < 0 || opt > std::size(menitms))) {

std::cout << "Invalid menu options\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

// If not quit option display and process
if (opt != std::size(menitms)) {
std::cout << "\nYou chose option " << menitms[opt].desc << " for " << menitms[opt].price << '\n';

// Process option here
}

// Loop until quit option
} while (opt != std::size(menitms));
}


Yea it works
1
2
3
4
5
/*

Zombie Sandwich Program by seeplus

*/


Slight correction to your code.......
Well what did you think was going to happen? :)
Topic archived. No new replies allowed.