Can I ask for help?

Please help me display the order summary properly if the customer ordered more than once.

PS.
My code's problem is it's only displaying the last input and cannot reflect the other inputs.

Please also post the correct code if you guys are able to fix it please.

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

using namespace std;


int main(){
	int code[10] = {1,2,3,4,5,6,7,8,9,10};
	char prod[10][30]= {"Apple","Banana","Orange","Berry","Grape","Peach","Pear","Lemon","Cherry","Apricot"};
	int price[10] = {15,25,35,45,55,65,75,85,95,105};
	int stock[10] = {10,10,10,10,10,10,10,10,10,10};
	int total;
	int k = 0;
	int ans;
	int m = 1;
	int item;
	
	do{
		cout<<"============ Ilao Fruit Store ============\n\t\t  Welcome!\n       We restock every transaction!\n\n1) Order \n2) Pay \n3) Exit\n\n";
		int choice;
		cout<<"Choice: ";
		cin>>choice;
		cout<<endl;
		
		if(choice == 1){
			do{
			cout<<"\nCode\t\tProduct\t\tPrice\t\tStock\n\n";
				for (int i = 0; i < 10; i++){
					cout<<code[i]<<"\t\t"<<prod[i]<<"\t\t"<<price[i]<<"\t\t"<<stock[i]<<"\n"<<endl;
				}
				
					
					cout<<"E1: What's your order?"<<endl;
					cout<<"Order #: "<<m<<endl;
					cout<<"(Please enter Item Code then Fruit)"<<endl;
					cout<<"C1: ";
					char prod[10];
					cin>>k;
					cout<<"C1: ";
					cin>>prod;
					cout<<"E1: How many?"<<endl;
					cout<<"C1: ";
					cin>>item;
						if(item>10||item<=0){
							cout<<"Invalid Transaction!!!"<<endl;
							cout<<"Goodbye! Please Shop again!";
							break;
						}
					cout<<"E1: Do you want to still order?\n1 for YES\n2 for NO"<<endl;
					cout<<"C1: ";
					cin>>ans;
					cout<<endl;
					cout<<endl;
				
			
					if(ans==1){
					m++;
					continue;		
					}else if(ans==2){
					break;	
			 	}
			 }while(1);
			 
			 
			 
					k = k - 1;
					total = price[k] * item;
						for(int j = 0; j < m; j++){
						
						cout<<"Order #: "<<m<<"\t\t"<<prod[k]<<" "<<item<<"  = "<<total<<endl; 
						}
					
		
				cout<<endl;
				
				stock[k] = stock[k] - item;
				
				
			}
		
		
	
		
		
		
		else if(choice == 2){
			cout<<"Balance: "<<total<<endl;
			cout<<"Payment: ";
			int payment;
			cin>>payment;
			cout<<"Change: "<<payment - total<<endl;
		}
	
		else if(choice == 3){
				cout<<"Thank you for shopping!";
			break;
		}else{
			cout<<"Invalid Input!!!";
			
		}
	cout<<endl;

	
		
	}while(1);

}
for(int j = 0; j < m; j++){

cout<<"Order #: "<<m<<"\t\t"<<prod[k]<<" "<<item<<" = "<<total<<endl;
}


at a guess, you need [j] NOT [k] here, unless you are doing something weird on purpose.
A good thing to do in the case of improper display would be to update the price through each iteration of the do loop, so that nothing is lost during calculation. You can still put in the individual purchases in it, and make the calculations smoother as well. Here's a rewrite of the code to show what I mean:


cout<<"E1: What's your order?"<<endl;
            cout<<"Order #: "<<m<<endl;
            cout<<"(Please enter Item Code)"<<endl;  //then Fruit)"<<endl; (don't need fruit name input)
            cout<<"C1: ";
            cin>>ans;
            cout<<"E1: How many?"<<endl;
            cout<<"C1: ";
            cin>>item;
            if(item>10||item<=0){
               cout<<"Invalid Transaction!!!"<<endl;
               cout<<"Goodbye! Please Shop again!";
               break;
            }
            cout<<"Order #: "<<m<<"\t\t"<<prod[ans]<<" "<<item<<"  = "<<price[ans]*item<<endl;
            ans = ans - 1;
            total+=price[ans]*item;
            ans=0;
            cout<<"E1: Do you want to still order?\n1 for YES\n2 for NO"<<endl;
            cout<<"C1: ";
            cin>>ans;
            cout<<endl;
            cout<<endl;


If you want, I also edited your code to take some redundant stuff out. If you want to take a look at it, just message me.
To the OP: please be wary of people trying to encourage you to discuss your issue in private messages. We have at least one persistent troll on the forums who maliciously gives bad advice to people, and he often tries to do it in PM's so that other people don't call him on it.

It's better for you if you get help publicly through the forum, because that way you can be sure that others will scrutinize what's been posted and can pick out problems with it.
Sorry, I wasn't aware of this troll either, and that wasn't my intention. I won't ask anyone to message me anymore.
Last edited on
Topic archived. No new replies allowed.