please help me

A) Write a program to automate the billing system for a restaurant. The program should do the following:

Show the customer the different items offered by the restaurant.
Allow the customer to select two items from the menu.
Calculate and print the bill.
Assume that the restaurant offers the following sandwich and drink items (5 items) (the price of each item is shown to the right of the item):

Falafel 0.80 JD

Kabab 2.80 JD

Shawarma 1.80 JD

Pepsi 0.50 JD

Juice 0.99 JD

Your program must contain at least the following functions:

Function showMenu that shows the different items offered by the restaurant and tells the user to select only two items from the menu.
Function printCheck: This function calculates and prints the bill. (Note that the billing amount should include a 10% tax.)


A sample output is:



Receopt.png



B) Update the previous program so that allows the customer to select multiple items and specify the count?

We can only help you improve your code if you post it.
I have tried but I have no ideas, I am a beginner in programming, and I hope to get some ideas and help
Show us what you've tried.

Read a tutorial, maybe. http://www.cplusplus.com/doc/tutorial/
Or start with the simplest shell of a program possible:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

void showMenu()
{
    cout << "This is the menu!\n";
}

int main()
{
    showMenu();
}


We aren't a homework service, but will answer specific questions if you ask them.
Last edited on
#include <iostream>
#include <string>
using namespace std;
void showmenu();
struct menu
{
double falafel;
double kabab;
double shawarma;
double pepsi;
double juice;
};
void main()
{
menu f, k, s, p, j;
f.falafel = 0.80;
k.kabab = 2.80;
s.shawarma = 1.80;
p.pepsi = 0.50;
j.juice = 0.99;
char y,x;
showmenu();
for (int i = 0; i < 2; i++)
{
cin >> x;
cin >> y;
}

}
void showmenu()
{
cout << "------menu------\n";
cout << "falafel = 0.80\n";
cout << "kabab = 2.80\n";
cout << "shawarma = 1.80\n";
cout << "pepsi = 0.50\n";
cout << "juice = 0.99\n";
cout << "Please enter the first letter of your choice: \n";
}
void printCheck()
{

}
I know that the program is wrong
I think that you understood me wrongly or that I did not explain to you but I want to learn, I do not want to write the program for me
Last edited on
Your loop for taking in input doesn't make sense. You want to take in two menu items, just you take in two menu items twice - which means you take in 4 menu items.

void main should be int main.

Is there a reason for the class? It doesn't seem necessary.

Looks like it does everything up to calculating the bill. For that you'll wanna either hard code it like this:

1
2
3
4
if(x == f)
   cost += .8;
if(x == k)
   //... etc .. 


Or you can do it a bit more sophisticated-like:

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
#include <iostream>
#include <string>
using namespace std;
void showmenu();
void printCheck(char x, char y);
struct menu
{
	double falafel;
	double kabab;
	double shawarma;
	double pepsi;
	double juice;
};
int main()
{
	menu f, k, s, p, j;
	f.falafel = 0.80;
	k.kabab = 2.80;
	s.shawarma = 1.80;
	p.pepsi = 0.50;
	j.juice = 0.99;
	char y, x;
	showmenu();
	cin >> x;
	cin >> y;
	x = toupper(x);
	y = toupper(y);
	while (x<'A' || x>'E' || y<'A' || y>'E')
	{
		cout << "Please Enter A Valid Option: ";
		cin >> x;
		cin >> y;
	}
	printCheck(x, y);
}
void showmenu()
{
	cout << "------menu------\n";
	cout << "A. falafel = 0.80\n";
	cout << "B. kabab = 2.80\n";
	cout << "C. shawarma = 1.80\n";
	cout << "D. pepsi = 0.50\n";
	cout << "E. juice = 0.99\n";
	cout << "Enter the letters of your TWO choices: \n";
}
void printCheck(char x, char y)
{
	double a[] = { 0.80, 2.80, 1.80, 0.50, 0.99 };
	//X and Y are characters between 'A' and 'E'
	//So if we subtract 'A' from them, we'll get the
	//Corresponding values between 0 and 4
	cout << a[x - 'A'] + a[y - 'A'];
}
Why should I type int main instead of void main ?
Because the Standard Says So™. But no return statement is needed in main (special case).
Last edited on
I don't need the struct?
can I write the code without the struct?
I can compute the tax by multiplying the result by 10%, right?
Correct, you don't need a struct. Structs are there to help you organize.

1
2
3
4
5
6
	menu f, k, s, p, j;
	f.falafel = 0.80;
	k.kabab = 2.80;
	s.shawarma = 1.80;
	p.pepsi = 0.50;
	j.juice = 0.99;

Doing this is outright silly. You probably meant:
1
2
3
4
5
6
	menu the_menu;
	the_menu.falafel = 0.80;
	the_menu.kabab = 2.80;
	the_menu.shawarma = 1.80;
	the_menu.pepsi = 0.50;
	the_menu.juice = 0.99;

But you don't need the struct, you could just have a bunch of doubles, or an array of doubles like zapshe shows, since you aren't actually using the menu object for anything. Alternatively, you could pass the menu as a parameter into printCheck.

For tax, you'd add to the total price by 10%, or multiply by 1.1.
Last edited on
Thank you for your help
I don't need the struct?
can I write the code without the struct?

So far, your program doesn't use the struct to accomplish anything:

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

using namespace std;

void showmenu();
void printCheck(char x, char y);

int main()
{
	char y, x;
	showmenu();
	cin >> x;
	cin >> y;
	x = toupper(x);
	y = toupper(y);
	while (x<'A' || x>'E' || y<'A' || y>'E')
	{
		cout << "Please Enter A Valid Option: ";
		cin >> x;
		cin >> y;
	}
	printCheck(x, y);
}
void showmenu()
{
	cout << "------menu------\n";
	cout << "A. falafel = 0.80\n";
	cout << "B. kabab = 2.80\n";
	cout << "C. shawarma = 1.80\n";
	cout << "D. pepsi = 0.50\n";
	cout << "E. juice = 0.99\n";
	cout << "Enter the letters of your TWO choices: \n";
}
void printCheck(char x, char y)
{
	double a[] = { 0.80, 2.80, 1.80, 0.50, 0.99 };
	//X and Y are characters between 'A' and 'E'
	//So if we subtract 'A' from them, we'll get the
	//Corresponding values between 0 and 4
	cout << a[x - 'A'] + a[y - 'A'];
}



This does the same thing. The struct seems like extra code since the menu items and their corresponding price appear to be static (unchanging).
Here's another way of going about it as a start. Maybe you can store the 2 selections in an array?

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

using namespace std;

struct Item
{
    string name;
    double price;
};

int showMenu(Item[], int);

int main()
{
    Item food_list[] // YOU CAN USE 2 SEPARATE ARRAYS INSTEAD OF A struct
    {
        {"Falafel",0.80},
        {"Kabab", 2.80},
        {"Shawarma", 1.80},
        {"Pepsi", 0.50},
        {"Juice", 0.99}
    };
    
    int item_count = sizeof(food_list)/sizeof(Item);
    
    for (int i = 0; i < 2; i++)
    {
        int selection = showMenu(food_list, item_count);
        cout
        << " *** You just ordered " << food_list[selection].name << '\n';
    }
    
    return 0;
}

int showMenu(Item list[], int no_items)
{
    cout << "------menu------\n";
    
    for(int i = 0; i < no_items; i++)
    cout
    << i << " - "
    << list[i].name << '\t'
    << list[i].price << '\n';
    
    cout << "Please enter the item number of your choice: ";
    int order{0};
    cin >> order;
    
    return order;
}

void printCheck()
{
    
}
Topic archived. No new replies allowed.