help...problem

i wrote a code, but the output shows very large numbers, and i do not know how to fix it..plz help me..

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
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{	
	const double Milk_chocolate_price=8.50;
	const double Dark_european_chocolate_price=9.75;	
	const double White_chocolate_price=10.50;
	const double European_truffles_price=12.50;
	
	int choice;
	double Milk_chocolate, Dark_european_chocolate, White_chocolate, European_truffles;
	double Milk_chocolate_total, Dark_european_chocolate_total, White_chocolate_total, European_truffles_total;
	double subtotal, discount_amount, discount_total, discount_percent, total,shipping, grand_total;
	char discount;
	
	cout<<"1 - Milk Chocolate\n2 - Dark_European Chocolate\n3 - White Chocolate\n4 - European Truffles";
			
	const int milk_chocolate=1;
	const int dark_european_chocolate=2;	   
	const int white_chocolate=3;
	const int european_truffles=4;
	
	cout<<fixed<<showpoint<<setprecision(2);
	
	bool again=true;
	char answer;
	
	while (again)
	{
		cout<<"\n\nEnter your choice: ";
		cin>>choice;
		switch (choice)
		{
			case milk_chocolate:
				cout<<"\nEnter the pounds of Milk Chocolate: ";
				cin>>Milk_chocolate;				
				break;
			case dark_european_chocolate:
				cout<<"\nEnter the pounds of Dark European Chocolate: ";
				cin>>Dark_european_chocolate;	 	 	 	 
				break;
			case white_chocolate:
				cout<<"\nEnter the pounds of White Chocolate: ";
				cin>>White_chocolate;	 
				break;
			case european_truffles:
				cout<<"\nEnter the pounds of European Truffles: ";
				cin>>European_truffles;
				break;
			default:
				cout<<"\nYou did not enter 1, 2, 3, 4.\nYou entered "<<choice;
		}
		cout<<"\n\nDo you wanna order another chocolate(y or n)? ";
		cin>>answer;
		switch (answer)
		{
			case 'y': 
				again = true;
         		break;
     		case 'n': 
				again = false;
         		break;
		}
	}
	if (Milk_chocolate>0)
	{
		Milk_chocolate_total=Milk_chocolate*Milk_chocolate_price;
		cout<<"\n"<<Milk_chocolate<<" pounds of Milk Chocolate @ $8.50\t $"<<Milk_chocolate_total;
	}
	if (Dark_european_chocolate>0)
	{
		Dark_european_chocolate_total=Dark_european_chocolate*Dark_european_chocolate_price;
		cout<<"\n"<<Dark_european_chocolate<<" pounds of Dark European Chocolate @ $9.75\t $"<<Dark_european_chocolate_total;
	}
	if (White_chocolate>0)
	{
		White_chocolate_total=White_chocolate*White_chocolate_price;
		cout<<"\n"<<White_chocolate<<" pounds of White Chocolate @ $10.50\t $"<<White_chocolate_total;
	}
	if (European_truffles>0)
	{
		European_truffles_total=European_truffles*European_truffles_price;
		cout<<"\n"<<European_truffles<<" pounds of European Truffles @ $12.50\t $"<<European_truffles_total;
	}
	subtotal=Milk_chocolate_total+Dark_european_chocolate_total+White_chocolate_total+European_truffles_total;
	if ((subtotal >= 20.00) && (subtotal <= 39.99))
	{
		discount = 'A';
	}
	if ((subtotal >= 40.00) && (subtotal <= 59.99))
	{
		discount = 'B';
	}
	if ((subtotal >= 60.00) && (subtotal <= 79.99))
	{
		discount = 'C';
	
	}
	if (subtotal >= 80.00)
	{
		discount = 'D';
	}
	switch(discount)
	{	
		case 'A': 
			discount_amount = 10;
			break;
		case 'B': 
			discount_amount = 15;
			break;
		case 'C': 
			discount_amount = 20;
			break;
		case 'D': 
			discount_amount = 25;
			break;
	}
	discount_total=0.1*subtotal;
	total=subtotal - discount_total;
	shipping = total * .10;
	grand_total = shipping + total;
	if (grand_total > 0)
	{
		cout << "\n\nSubtotal $" << subtotal << "\n\nLess: " << discount_amount << "% Discount $" << discount_total <<"Total $"<<total<< "\nShipping and Handling 10% $" << shipping << "\n\nGrand Total $" << grand_total;
	}	 
	else 
		cout << "\nYou did not order any quantity.";
	return 0;
}


output
1 - Milk Chocolate
2 - Dark_European Chocolate
3 - White Chocolate
4 - European Truffles

Enter your choice: 1

Enter the pounds of Milk Chocolate: 3


Do you wanna order another chocolate(y or n)? n

3.00 pounds of Milk Chocolate @ $8.50    $25.50
0.00 pounds of Dark European Chocolate @ $9.75   $0.00
0.00 pounds of White Chocolate @ $10.50  $0.00
68771256577280777504780099248251138519061914723378405101400745634770837637401766
37071868757586793935434819639036292447698821852527354139009005763401435335650100
03048054528071451916142475847319439153181871671600524801606802534285536051108198
9633859332001417396224.00 pounds of European Truffles @ $12.50   $85964070721600
96838501517307460088550005005775055619842731988075310068944891899234925480412890
42406791065997574081996112060361913819999707184240008830080163727071630423897857
24351540761237250102403759369825798668500590470465070912229709617797964304228290
775744512.00

Subtotal $8596407072160096838501517307460088550005005775055619842731988075310068
94489189923492548041289042406791065997574081996112060361913819999707184240008830
08016372707163042389785724351540761237250102403759369825798668500590470465070912
229709617797964304228290775744512.00

Less: 25.00% Discount $859640707216009718809751240603139231488273934042230063767
50932043463547046752207963398359469834924192935245487953655596235273156591926737
61257204251794169562625038100681600893148951780948091492989414773395895006560020
085031678569200638852487042324165001771745280.00Total $7736766364944086595297773
41899999367120013149296336858654982106132100483474939481316996351705247229890701
06612794650074038653427907917146615944734178813327929767297995068850020495623407
923661368178762050230176566291154815655820173364052404702233573930698591436800.0
0
Shipping and Handling 10% $77367663649440865952977734189999936712001314929633685
86549821061321004834749394813169963517052472298907010661279465007403865342790791
71466159447341788133279297672979950688500204956234079236613681787620502301765662
9115481565582017336405240470223357393069859143680.00

Grand Total $8510443001438495254827550760899993038320144642259705445204803167453
10531822433429448695986875771952879771172740741150814425187706987088612775392075
96694660722744027794575735022545185748716027504996638255253194222920270297221402
190700457645172456931323768450580480.00
Press Enter to return to Quincy...
Last edited on
subtotal=Milk_chocolate_total+Dark_european_chocolate_total+White_chocolate_total+European_truffles_total; you may want to give them all an initial value of 0 otherwise you could be adding undefined values to the subtotal.
That might be because you did not initialize the variables to a specific number say zero, so the PC assigned any random number to those vars, and so this result.

Aceix.
thx guys

do u guys mean:const double Milk_chocolate_total=0, Dark_european_chocolate_total=0, White_chocolate_total=0, European_truffles_total=0;
this is assignment of read-only variables
i still have no idea... :(
Last edited on
No not a constant, but like this:
1
2
double Milk_chocolate_total=0, Dark_european_chocolate_total=0, White_chocolate_total=0, European_truffles_total=0;
double subtotal=0, discount_amount=0, discount_total=0, discount_percent=0, total,shipping=0, grand_total=0;


Aceix.
it does not work... :(
this is my new code..changed as you said
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
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{	
	const double Milk_chocolate_price=8.50;
	const double Dark_european_chocolate_price=9.75;	
	const double White_chocolate_price=10.50;
	const double European_truffles_price=12.50;
	
	int choice;
	double Milk_chocolate, Dark_european_chocolate, White_chocolate, European_truffles;
	double Milk_chocolate_total=0, Dark_european_chocolate_total=0, White_chocolate_total=0, European_truffles_total=0;
	double subtotal=0, discount_amount=0, discount_total=0, discount_percent=0, total=0 ,shipping=0, grand_total=0;
	char discount;
	
	cout<<"1 - Milk Chocolate\n2 - Dark_European Chocolate\n3 - White Chocolate\n4 - European Truffles";
			
	const int milk_chocolate=1;
	const int dark_european_chocolate=2;	   
	const int white_chocolate=3;
	const int european_truffles=4;
	
	cout<<fixed<<showpoint<<setprecision(2);
	
	bool again=true;
	char answer;
	
	while (again)
	{
		cout<<"\n\nEnter your choice: ";
		cin>>choice;
		switch (choice)
		{
			case milk_chocolate:
				cout<<"\nEnter the pounds of Milk Chocolate: ";
				cin>>Milk_chocolate;				
				break;
			case dark_european_chocolate:
				cout<<"\nEnter the pounds of Dark European Chocolate: ";
				cin>>Dark_european_chocolate;	 	 	 	 
				break;
			case white_chocolate:
				cout<<"\nEnter the pounds of White Chocolate: ";
				cin>>White_chocolate;	 
				break;
			case european_truffles:
				cout<<"\nEnter the pounds of European Truffles: ";
				cin>>European_truffles;
				break;
			default:
				cout<<"\nYou did not enter 1, 2, 3, 4.\nYou entered "<<choice;
		}
		cout<<"\n\nDo you wanna order another chocolate(y or n)? ";
		cin>>answer;
		switch (answer)
		{
			case 'y': 
				again = true;
         		break;
     		case 'n': 
				again = false;
         		break;
		}
	}
	if (Milk_chocolate>0)
	{
		Milk_chocolate_total=Milk_chocolate*Milk_chocolate_price;
		cout<<"\n"<<Milk_chocolate<<" pounds of Milk Chocolate @ $8.50\t $"<<Milk_chocolate_total;
	}
	if (Dark_european_chocolate>0)
	{
		Dark_european_chocolate_total=Dark_european_chocolate*Dark_european_chocolate_price;
		cout<<"\n"<<Dark_european_chocolate<<" pounds of Dark European Chocolate @ $9.75\t $"<<Dark_european_chocolate_total;
	}
	if (White_chocolate>0)
	{
		White_chocolate_total=White_chocolate*White_chocolate_price;
		cout<<"\n"<<White_chocolate<<" pounds of White Chocolate @ $10.50\t $"<<White_chocolate_total;
	}
	if (European_truffles>0)
	{
		European_truffles_total=European_truffles*European_truffles_price;
		cout<<"\n"<<European_truffles<<" pounds of European Truffles @ $12.50\t $"<<European_truffles_total;
	}
	subtotal=Milk_chocolate_total+Dark_european_chocolate_total+White_chocolate_total+European_truffles_total;
	if ((subtotal >= 20.00) && (subtotal <= 39.99))
	{
		discount = 'A';
	}
	if ((subtotal >= 40.00) && (subtotal <= 59.99))
	{
		discount = 'B';
	}
	if ((subtotal >= 60.00) && (subtotal <= 79.99))
	{
		discount = 'C';
	
	}
	if (subtotal >= 80.00)
	{
		discount = 'D';
	}
	switch(discount)
	{	
		case 'A': 
			discount_amount = 10;
			break;
		case 'B': 
			discount_amount = 15;
			break;
		case 'C': 
			discount_amount = 20;
			break;
		case 'D': 
			discount_amount = 25;
			break;
	}
	discount_total=0.1*subtotal;
	total=subtotal - discount_total;
	shipping = total * .10;
	grand_total = shipping + total;
	if (grand_total > 0)
	{
		cout << "\n\nSubtotal $" << subtotal << "\n\nLess: " << discount_amount << "% Discount $" << discount_total <<"Total $"<<total<< "\nShipping and Handling 10% $" << shipping << "\n\nGrand Total $" << grand_total;
	}	 
	else 
		cout << "\nYou did not order any quantity.";
	return 0;
}


1 - Milk Chocolate
2 - Dark_European Chocolate
3 - White Chocolate
4 - European Truffles

Enter your choice: 3

Enter the pounds of White Chocolate: 3


Do you wanna order another chocolate(y or n)? n

0.00 pounds of Milk Chocolate @ $8.50    $0.00
3.00 pounds of White Chocolate @ $10.50  $31.50
68771256577280777504780099248251138519061914723378405101400745634770837637401766
37071868757586793935434819639036292447698821852527354139009005763401435335650100
03048054528071451916142475847319439153181871671600524801606802534285536051108198
9633859332001417396224.00 pounds of European Truffles @ $12.50   $85964070721600
96838501517307460088550005005775055619842731988075310068944891899234925480412890
42406791065997574081996112060361913819999707184240008830080163727071630423897857
24351540761237250102403759369825798668500590470465070912229709617797964304228290
775744512.00

Subtotal $8596407072160096838501517307460088550005005775055619842731988075310068
94489189923492548041289042406791065997574081996112060361913819999707184240008830
08016372707163042389785724351540761237250102403759369825798668500590470465070912
229709617797964304228290775744512.00

Less: 25.00% Discount $859640707216009718809751240603139231488273934042230063767
50932043463547046752207963398359469834924192935245487953655596235273156591926737
61257204251794169562625038100681600893148951780948091492989414773395895006560020
085031678569200638852487042324165001771745280.00Total $7736766364944086595297773
41899999367120013149296336858654982106132100483474939481316996351705247229890701
06612794650074038653427907917146615944734178813327929767297995068850020495623407
923661368178762050230176566291154815655820173364052404702233573930698591436800.0
0
Shipping and Handling 10% $77367663649440865952977734189999936712001314929633685
86549821061321004834749394813169963517052472298907010661279465007403865342790791
71466159447341788133279297672979950688500204956234079236613681787620502301765662
9115481565582017336405240470223357393069859143680.00

Grand Total $8510443001438495254827550760899993038320144642259705445204803167453
10531822433429448695986875771952879771172740741150814425187706987088612775392075
96694660722744027794575735022545185748716027504996638255253194222920270297221402
190700457645172456931323768450580480.00
Press Enter to return to Quincy...
Last edited on
well you still have some undefined variables:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	if (Milk_chocolate>0)
	{
		Milk_chocolate_total=Milk_chocolate*Milk_chocolate_price;
		cout<<"\n"<<Milk_chocolate<<" pounds of Milk Chocolate @ $8.50\t $"<<Milk_chocolate_total;
	}
	if (Dark_european_chocolate>0)
	{
		Dark_european_chocolate_total=Dark_european_chocolate*Dark_european_chocolate_price;
		cout<<"\n"<<Dark_european_chocolate<<" pounds of Dark European Chocolate @ $9.75\t $"<<Dark_european_chocolate_total;
	}
	if (White_chocolate>0)
	{
		White_chocolate_total=White_chocolate*White_chocolate_price;
		cout<<"\n"<<White_chocolate<<" pounds of White Chocolate @ $10.50\t $"<<White_chocolate_total;
	}
	if (European_truffles>0)
	{
		European_truffles_total=European_truffles*European_truffles_price;
		cout<<"\n"<<European_truffles<<" pounds of European Truffles @ $12.50\t $"<<European_truffles_total;
	}


Most of those will be undefined when you check the if statement.

double Milk_chocolate, Dark_european_chocolate, White_chocolate, European_truffles;

should be double Milk_chocolate=0.0, Dark_european_chocolate=0.0, White_chocolate=0.0, European_truffles=0.0;
Last edited on
thx
it works..:)
Last edited on
Topic archived. No new replies allowed.