Need Help with Tables

I've been trying to make a Menu ordering system that displays the Items ordered only, much like a receipt, but everytime i order again the row seems to be seems to be replaced by the newer row.
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
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>



int main(){
clrscr();
const int cb=20,fl=20,yb=20,drinks=20,coke=20,
sprite=20,royal=20,pj=25,med=5,large=10;
int total,cash,change,quantity;
int order = 1;
const char *items[]={"Cheese Buger","Foot Long","Yum Burger","Drinks","Coke"
,"Sprite","Royal","Pineapple Juice"};
char loop; 
int rows;  
int itemElements = sizeof(items)/sizeof(items[0]);

cout << "\t"<<setw(10) << "Item" << "\t" << " Price" <<"\t"<< "\n";
cout << "\t" << "Cheese Burger" << "\t" << setw(5)<<cb << "\n";
cout << "\t" << "Foot Long" << "\t" <<setw(5)<< fl << "\n";
cout << "\t" << "Yum Burger" << "\t" <<setw(5)<< yb << "\n";
cout << "\t" << "Water" << "\t" <<setw(14)<< drinks << "\n";
cout << "\t" << "Coke" << "\t" <<setw(14) <<coke << "\n";
cout << "\t" << "Sprite" << "\t" <<setw(14) <<sprite << "\n";
cout << "\t" << "Royal" << "\t" <<setw(14) <<royal << "\n";
cout << "\t" << "P.J" << "\t"<<setw(14)<< pj << "\n";
cout << "\t" << "Med" << "\t" <<setw(14)<< med << "\n";
cout << "\t" << "Large" << "\t" <<setw(14) <<large << "\n";
cout << "Hi, Sir/Maam welcome to boboys! What would you like?" << "\n" ;
struct food{
char itemName;
int price;
};
food f;
do{
cin >> order;
switch(order)
{
	case 0:
	break;
	case 1:
	cout << "How many Chesse Burgers do you Like?\n";
	cin >> quantity;
	total=cb * quantity;
	break;

	case 2:
	cout << "How many Foot longs do you like?\n";
	cin >> quantity;
	total = fl * quantity;
	break;

		case 3:
	cout << "How many Yum Burgers do you like?\n";
	cin >> quantity;
	total = yb * quantity;
	break;

		case 4:
	cout << "How many Waters do you like?\n";
	cin >> quantity;
	total = drinks * quantity;
	break;

		case 5:
	cout << "How many Cokes do you like?\n";
	cin >> quantity;
	total = coke * quantity;
	break;

		case 6:
	cout << "How many Royals do you like?\n";
	cin >> quantity;
	total = royal * quantity;
	break;

		case 7:
	cout << "How many Sprites do you like?\n";
	cin >> quantity;
	total = sprite * quantity;
	break;

		case 8:
	cout << "How many Pine Apple Juices do you like?\n";
	cin >> quantity;
	total = pj * quantity;
	break;



default: cout << "Please select a Valid Order!";
}
cout << "Cash on Hand: ";
cin >> cash;

change = total - cash;
cout << "You Have Ordered \n";
cout << "======================================================\n";
cout << setw(15) << "ITEM" <<setw(15)<< "QUANTITY"<<setw(15)<< "PRICE\n";
cout << "=====================================================\n";
	cout <<items[order-1]<<setw(15)<<quantity<<setw(15)<<total;
	cout << "\n";
cout << "Would you like to Order Again? Y/N " ;
cin >> loop;

 } while(loop == 'Y'|| loop == 'y');
cout << "Thank You, Your total Bill is: " << total;
getche();
return 0;
}


Any help or hint is appreciated dearly.
Last edited on
well..since you said any help or hint...I will give you one help and/or hint
when using standard C++ library do not put .h at the end
i.e iostream.h instead of iostream
so....
here are the libraries that got changed ( note : I could not compile them in https://ideone.com/8Dz8nG so, that's why I am telling you to change the include )

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

from that to

#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstdio>


for string, you can just use the string class that is available for C++
amd for your array of string,
I would recommend either vector or the array class if available

#include <array> / #include<vector>

1
2
3
4
5
std::vector< string > items;
items.emplace_back( "cheese burger" );
...
items.emplace_back( "pineaple juice" );
items.size(); //to get the size 


I suppose that is all, and since you aren't using stdio and stdlib, why include them ?
Last edited on
The problem is that you never store the items ordered, only add the price to the total.
You need to find a way to store each ordered item, then you can print them all at the end.
A vector would be the normal choice but I am afraid your very very old compiler might not have it.
So the first step might be to get a modern compiler.
Our school wanted us to use Turbo C++
Our school wanted us to use Turbo C++
Ok resistance would be futile.

Maybe there is a without using vector.
Can you show us the complete assignment?
hmmmm, how do i store it in an array? although I got a rudimentary one and i'm also quite not sure if it actually stores the values and how do I print it out using cout?

here's the revise code
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
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/*
  ELIJAH ABGAO n FRIENDS!
*/

int main(){
clrscr();
const int cb=20,fl=20,yb=20,drinks=20,coke=20,
sprite=20,royal=20,pj=25,med=5,large=10; //price Variable
int total,cash,change;  //the 3 idiots
int currentOrder=0;
int quantity[12];  //quantity array
int order[12]={currentOrder};   //order array
int rows,coloumns; //loop specific
const char *items[100]={"Cheese Buger","Foot Long","Yum Burger","Drinks","Coke"
,"Sprite","Royal","Pineapple Juice"};
char loop; //prevent the program from aborting prematurely
cout << "\t"<<setw(10) << "Item" << "\t" << " Price" <<"\t"<< "\n";
cout << "\t" << "Cheese Burger" << "\t" << setw(5)<<cb << "\n";
cout << "\t" << "Foot Long" << "\t" <<setw(5)<< fl << "\n";
cout << "\t" << "Yum Burger" << "\t" <<setw(5)<< yb << "\n";
cout << "\t" << "Water" << "\t" <<setw(14)<< drinks << "\n";
cout << "\t" << "Coke" << "\t" <<setw(14) <<coke << "\n";
cout << "\t" << "Sprite" << "\t" <<setw(14) <<sprite << "\n";
cout << "\t" << "Royal" << "\t" <<setw(14) <<royal << "\n";
cout << "\t" << "P.J" << "\t"<<setw(14)<< pj << "\n";
cout << "\t" << "Med" << "\t" <<setw(14)<< med << "\n";
cout << "\t" << "Large" << "\t" <<setw(14) <<large << "\n";
cout << "Hi, Sir/Maam welcome to boboys! What would you like?" << "\n" ;
do{
cin >> order[currentOrder];
switch(order[currentOrder])
{
	case 0:
	break;
	case 1:
	cout << "How many Chesse Burgers do you Like?\n";
	cin >> quantity[currentOrder];
	total =cb * quantity[currentOrder];
	break;

	case 2:
	cout << "How many Foot longs do you like?\n";
	cin >> quantity[currentOrder];
	total = fl * quantity[currentOrder];
	break;

		case 3:
	cout << "How many Yum Burgers do you like?\n";
	cin >> quantity[currentOrder];
	total = yb * quantity[currentOrder];
	break;

		case 4:
	cout << "How many Waters do you like?\n";
	cin >> quantity[currentOrder];
	total = drinks * quantity[currentOrder];
	break;

		case 5:
	cout << "How many Cokes do you like?\n";
	cin >> quantity[currentOrder];
	total = coke * quantity[currentOrder];
	break;

		case 6:
	cout << "How many Royals do you like?\n";
	cin >> quantity[currentOrder];
	total = royal * quantity[currentOrder];
	break;

		case 7:
	cout << "How many Sprites do you like?\n";
	cin >> quantity[currentOrder];
	total = sprite * quantity[currentOrder];
	break;

		case 8:
	cout << "How many Pine Apple Juices do you like?\n";
	cin >> quantity[currentOrder];
	total= pj * quantity[currentOrder];
	break;



default: cout << "Please select a Valid Order!";
}
cout << "Cash on Hand: ";
cin >> cash;

change = total - cash;
cout << "You Have Ordered \n";
cout << "======================================================\n";
cout << setw(15) << "ITEM" <<setw(15)<< "QUANTITY"<<setw(15)<< "PRICE\n";
cout << "=====================================================\n";

	cout << items[order[currentOrder]-1] << quantity[currentOrder] << total <<endl;

cout << "Would you like to Order Again? Y/N " ;
cin >> loop;

 } while(loop == 'Y'|| loop == 'y');
cout << "Thank You, Your total Bill is: " << total;
getche();
return 0;
}


as for the assignment, we were only given a note to make a food ordering system with tables on it.
Last edited on
Two obvious problems.
1. You need to increment currentOrder otherwise you will always store everything in the first row.
2. You need to add the subtotal to total not overriding it.

Why is an oder 0 ignored? 0 refers to Cheese Burger
I forgot to change that as well, it was used for exiting the program when i press 0.
How do i go about incrementing currentOrder, do i just add ++ at cout?

Forgive my Noobiness.
Last edited on
After taking the order use currentOrder++
Topic archived. No new replies allowed.