how to hide user input

I wrote this code that takes in menu items from a txt file and shows it to the user. Each item has a specific number, the user then inputs the number of their desired item. How can I hide the number that the user inputs and only show the name of the item. I've tried using getch() but it still shows the number. Maybe I'm using it wrong. Any ideas of how to do this?
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <iostream>
#include <iomanip>
#include <string> 
#include <fstream>
#include <cstdlib>
#include <conio.h>

using namespace std; 

const double tax_rate = 0.05;

struct menuItemType
{
	string ItemName;
	double ItemPrice;
};

void getData(ifstream &in, menuItemType menuList[]);
void showMenu(menuItemType menuList[]);
void printCheck(menuItemType menuList[]);


int main()
{
	menuItemType menuList[10];
	menuList[10].ItemName; 
	menuList[10].ItemPrice;

	ifstream in;
	in.open("Menu.txt");
	cout << "Welcome to Johnny's Breakfast Diner!" << endl;

	getData(in,menuList);
	showMenu(menuList);

	return 0;
}

void getData(ifstream &in, menuItemType menuList[])
{
	int i = 0;
	while (!in.eof())
	{
		in >> menuList[i].ItemName >> menuList[i].ItemPrice;
		i++;
	}
	
}

void showMenu(menuItemType menuList[])
{
	
	int j = 0;
	char answ;

	cout << fixed << setprecision(2);
	cout << "Would you like to take a look at our menu? (Y/N)";
	cin >> answ;
	if (answ == 'Y' || answ == 'y')
	{
		cout << left << setw(10) << "Item#" << left << setw(15) << "Item" << left << setw(18) <<  "Price" << endl;
		do {
		{
			cout << left << setw(8) << j << " " << left << setw(15) << menuList[j].ItemName << " " << "$" <<  menuList[j].ItemPrice << endl;
			j++;
		}
	} while (j < 8);
		printCheck(menuList);

	}
	
	else if (answ == 'N' || answ == 'n')
	{
		system("cls");
		cout << "Have a good day!" << endl;
	}

}

void printCheck(menuItemType menuList[])
{
	ofstream out;
	out.open ("Receipt.txt");
	char answ;
	int choice;
	bool menu = true;
	double subtotal = 0.0;
	char ch[1];

	out << fixed << setprecision(2);

	cout << "Would like to place your order (Y/N)"; 
	cin >> answ;

	if (answ == 'Y' || answ == 'y') 
	{
		cout << "Please enter the number of the item, 8 to finish order:";
		out << "Welcome to Johnny's Breakfast Diner!" << endl;
		
		do {
			cin >> choice; 
			for (int i=0; i<1; i++)
			{
				ch[i] = getch();
				cout << ' ';
			}
			if (choice == 0)
			{
			cout << menuList[0].ItemName << left << setw(4) << " " << "$" << menuList[0].ItemPrice << endl;
			out << menuList[0].ItemName << left << setw(4) << " " << "$" << menuList[0].ItemPrice << endl;
			subtotal = subtotal + menuList[0].ItemPrice;
			}
			
			else if (choice == 1)
			{
				cout << menuList[1].ItemName << left << setw(3) << " " << "$" << menuList[1].ItemPrice << endl;
				out << menuList[1].ItemName << left << setw(3) << " " << "$" << menuList[1].ItemPrice << endl;
				subtotal = subtotal + menuList[1].ItemPrice;
			}

			else if (choice == 2)
			{
				cout << menuList[2].ItemName << left << setw(6) << " " << "$" << menuList[2].ItemPrice << endl;
				out << menuList[2].ItemName << left << setw(6) << " " << "$" << menuList[2].ItemPrice << endl;
				subtotal = subtotal + menuList[2].ItemPrice;
			}

			else if (choice == 3)
			{
				cout << menuList[3].ItemName << left << setw(1) << " " << "$" << menuList[3].ItemPrice << endl;
				out << menuList[3].ItemName << left << setw(1) << " " << "$" << menuList[3].ItemPrice << endl;
				subtotal = subtotal + menuList[3].ItemPrice;
			}

			else if (choice == 4)
			{
				cout << menuList[4].ItemName << left << setw(1) << " " << "$" << menuList[4].ItemPrice << endl;
				out << menuList[4].ItemName << left << setw(1) << " " << "$" << menuList[4].ItemPrice << endl;
				subtotal = subtotal + menuList[4].ItemPrice;
			}

			else if (choice == 5)
			{
				cout << menuList[5].ItemName << left << setw(6) << " " << "$" << menuList[5].ItemPrice << endl;
				out << menuList[5].ItemName << left << setw(6) << " " << "$" << menuList[5].ItemPrice << endl;
				subtotal = subtotal + menuList[5].ItemPrice;
			}

			else if (choice == 6)
			{
				cout << menuList[6].ItemName << left << setw(6) << " " << "$" << menuList[6].ItemPrice << endl;
				out << menuList[6].ItemName << left << setw(6) << " " << "$" << menuList[6].ItemPrice << endl;
				subtotal = subtotal + menuList[6].ItemPrice;
			}

			else if (choice == 7)
			{
				cout << menuList[7].ItemName << left << setw(9) << " " << "$" << menuList[7].ItemPrice << endl;
				out << menuList[7].ItemName << left << setw(9) << " " << "$" << menuList[7].ItemPrice << endl;
				subtotal = subtotal + menuList[7].ItemPrice;
			}

			else if (choice == 8)
			{
				break;
			}
		}while(menu = true);

	double tax = (subtotal * tax_rate);
	double total = (tax + subtotal);
	cout << "Taxes" << left << setw(7) << " " << "$" << tax << endl;
	out << "Taxes" << left << setw(7) << " " << "$" << tax << endl;
	cout << "Amount Due" << left << setw(2) << " " << "$" << total << endl;
	out << "Amount Due" << left << setw(2) << " " << "$" << total << endl;

	}



	else if (answ == 'N' || answ == 'n') 
	{
		system("cls");
		cout << "Ok, maybe I can help you at a later time." << endl;
	}


}


I put the whole code if you wanted to test it, but the problem is only located in the printCheck function.
This is what is inside the txt file just incase it is needed.
PlainEgg 1.45
Bacon&Egg 2.45
Muffin 0.99
FrenchToast 1.99
FruitBasket 2.49
Cereal 0.69
Coffee 0.50
Tea 0.75

Also I'm using break in the else if statement ( answ == 8) because I can't seem to break out of the do while by setting menu equal to false. But I'm still working to fix it.
Last edited on
The getch() on line 104 only gets the new line left from line 101.

Instead of this:
1
2
3
4
5
6
			cin >> choice; 
			for (int i=0; i<1; i++)
			{
				ch[i] = getch();
				cout << ' ';
			}
try this: choice = getch() - '0'; // Note - '0' converts the character to number (if valid)

On line 167 you assign true to menu. What you want is to compare it. So either }while(menu == true); or }while(menu);
Last edited on
Topic archived. No new replies allowed.