Hello how to declare the quantity in the problem?

Write your question here.

Here's the sample run of the problem:
LUNCH ORDER
===========================
ORDER OF HAMBURGERS : 3
ORDER OF FRENCH FRIES : 0
ORDER OF SOFT DRINKS : 2

LUNCH BILL
===================================
ITEM COST QUANTITY
-----------------------------------
HAMBURGER 100.00 3
FRENCH FRIES 35.50 0
SOFT DRINK 12.50 2

PLEASE PAY 325.00
THANK YOU!!

AND THIS IS WHAT IVE DONE 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
#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
const float SOFT_DRINK_PRICE = 12.50;
const float HAMBURGER_PRICE = 100.00;
const float FRENCH_FRIES_PRICE = 35.50;

int main(int argc, char *argv[]) 
    {
    	float bill;
    	
    	cout << "LUNCH ORDER" << endl;
    	cout << "======================" << endl;
    	cout << "ORDER OF HAMBURGERS : ";
    	cin >> bill;
    	cout << "ORDER OF FRENCH FRIES :";
    	cin >> bill;
    	cout << "ORDER OF SOFT DRINKS : ";
    	cin >> bill;
    	cout << "\n";
    	cout << "LUNCH BILL" << endl;
    	cout << "==============================" << endl;
    	cout << "ITEM          COST    QUANTITY" << endl;
    	cout << "------------------------------" << endl;
        cout << "HUMBERGERS" << HAMBURGER_PRICE << bill << endl;
        cout << "FRENCH FRIES" << FRENCH_FRIES_PRICE << bill << endl;
        cout << "SOFT DRINKS" << SOFT_DRINK_PRICE << bill << endl;
        cout << "\nPLEASE PAY " << SOFT_DRINK_PRICE + HAMBURGER_PRICE + FRENCH_FRIES_PRICE << endl;
        cout << "THANK YOU" << endl;
    	
 	 
 	 
     
	return 0;
}
Last edited on
Do you realise that at line 16, you read a value into bill, then at line 18 you overwrite it with a new value, and then at 20 you overwrite it again with a third value? So you're throwing away the first two values entered by the user, and then treating the third number as if it was the order for all three things?

For clarity and simplicity, since you're a beginner, you're going to want:

3 separate variables, to store the number of items of each type ordered by the customer. These should be int because you can only order whole numbers of items.

3 more variables, to store the total cost of each type of item. These should be float, as you're already using floating-point prices.

1 more variable to store the total cost of the bill. This will, obviously, be the sum of the totals for the 3 types of item. This should also be a float.
Hi there

I would do that with use of loop and user input, you will have to integrate this with your code ;) I have hard coded values of the food and soft drinks. it would be good idea to create possibly functions for each menu entry. but this would require a bit more code :D

for example

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

#include <iostream>
#include <cstdlib>
using namespace std;


int main()
{
	int customer_choice = 0;
	int soft_drink = 0;
	int hamburger = 0;
	int fries = 0;
	while (customer_choice != 8)
	{
		cout << "Please make your selection: " << endl;
		cout << "Press 1 for soft drink" << endl;
		cout << "Press 2 for Hamburger" << endl;
		cout << "Press 3 for Fries" << endl;
		cout << "To finish press 8" << endl;


		cin >> customer_choice;


		if (customer_choice == 1)
		{
			cout << "How many soft drinks do you like?" << endl;
			cin >> soft_drink;
		}
		if (customer_choice == 2)
		{
			cout << "How many hamburgers do you like?" << endl;
			cin >> hamburger;
		}
		if (customer_choice == 3)
		{
			cout << "How many Fries do you like?" << endl;
			cin >> fries;
		}


	}

	cout << "Order summary: " << endl;
	double soft_drink_total = soft_drink * 12.50;
	cout << "1. Soft drinks: " << soft_drink_total << endl;
	double hamburger_total = hamburger * 100.00;
	cout << "2.Hamburger total: " << hamburger_total << endl;
	double fries_total = fries * 35.50;
	cout << "3. Fries total: " << fries_total << endl;

	double final_bill = soft_drink_total + hamburger_total + fries_total;

	cout << "Total cost of the food and drinks: " << final_bill << endl;


	system("pause"); 


    return 0;
}
Thankyou Mikeyboy and to you, xxvms :) :) :) :)
MikeyBoyd

do you think is better to use float or double for this kind of problem?
I read somewhere that double is better then float, I think it was about precision???

thanks :)
Use double as the default floating point type.

It is not just about precision (or long double would be the default floating point type).

It is not for nothing that the a conversion from float to double is a promotion,
or that the type of a floating point literal without a type suffix eg. 2.3 is double,
or that functions like std::sqrt(), when invoked with an integral argument yield a result of type double
Topic archived. No new replies allowed.