Infinite Loop

Hey all i would appreciate any help here. I had to create a menu and did so, but the problem is every a letter is pressed instead of a number the code goes into an infinite loop, how would i stop that from happening???
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
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <iomanip>


using namespace std;


int main()
{
char choice='Y';

int order = 1;

int num1=0, num2=0, num3=0, num4=0, num5=0,num6=0,num7=0,num8=0;
int num_customers;
int sentinel=0;
const double UnitPrice1= 6.95, UnitPrice2= 5.75,UnitPrice3= 7.25, UnitPrice4= 8.95, UnitPrice5= 4.95,UnitPrice6=3.55, UnitPrice7= 1.55, UnitPrice8= 1.05;
double AmountofSale1=0, AmountofSale2=0, AmountofSale3=0, AmountofSale4=0, AmountofSale5=0, AmountofSale6=0, AmountofSale7=0,  AmountofSale8=0;


cout<<"___________________Menu________________\n\n"
     <<"_____(1) Cheese_Burger & Fries  $6.95_____\n"
     <<"_____(2) 6 Boneless_Wings       $5.75_____\n"
	 <<"_____(3) Steak                  $7.25_____\n"
	 <<"_____(4) 6 Shrimp_Nuggets       $8.95_____\n"
	 <<"_____(5) Giant Slice Of Pizza   $4.95_____\n"
     <<"_____(6) Super_Salad            $3.55_____\n"
     <<"_____(7) Fountain_Drinks        $1.55_____\n"
     <<"_____(8) Green_Tea              $1.00_____\n";
	 


while (order != sentinel)
{
cout<<"Please Enter Number Of Desired Item:\n";
cin>>order;     
         
switch(order)
			{
                
                case 0:
                break;
                
				case 1:
                     
                cout<<"How many Cheese Burgers would you like to order:\n";
                               cin>>num1;
                
                AmountofSale1 = UnitPrice1 * num1;
                break;
                
                
          
                 
				case 2: 
                cout<<"How many Boneless Wings would you like to order:\n";
				               cin>>num2;
               
                AmountofSale2= UnitPrice2 * num2;
                break;
                
                
                case 3: 
                cout<<"How many Steaks would you like to order:\n";
                                  cin>>num3;
                
                AmountofSale3= UnitPrice3 * num3;
                break;
                
                
                 
                case 4: 
                cout<<"How many orders Of Shrimp Nuggets would you like to order:\n";
                                cin>>num4;
                
                AmountofSale4= UnitPrice4 * num4;
                break;
                
                
                
                case 5: 
                cout<<"How many Slices Of Pizza would you like to order:\n";
                                cin>>num5;
                
                AmountofSale5= UnitPrice5 * num5; 
                break;
                
                
                case 6: 
                cout<<"How many Salads would you like to order:\n";
                                cin>>num6;
                
                AmountofSale6= UnitPrice6 * num6; 
                break;
                
                
                case 7: 
                cout<<"How many Fountain Drinks would you like to order:\n";
                                cin>>num7;
                
                AmountofSale7= UnitPrice7 * num7; 
                break;
                
                
                case 8: 
                cout<<"How many Green Teas would you like to order:\n";
                                cin>>num8;
                
                AmountofSale8= UnitPrice8 * num8; 
                break;
                
                
                default: cout<<"Please choose a valid item from our list\n";
                }
                

{       
        system("cls");

cout<<"You have ordered:\n\n";

cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";


cout<<"<1> Cheese Burgers:"<<setw(6)<<left<< num1 <<setw(16)<<right<< UnitPrice1 <<setw(20) <<right<< AmountofSale1<<endl;

cout<<"<2> Bonless Wings:"<<setw(6)<<left<< num2 <<setw(16)<<right<< UnitPrice2 <<setw(21) <<right<< AmountofSale2<<endl<<endl;

cout<<"<3> Steaks:"<<setw(8)<<left<< num3 <<setw(16)<<right<< UnitPrice3 <<setw(27) <<right<< AmountofSale3<<endl<<endl;

cout<<"<4> Shrimp Nuggets:"<<setw(6)<<left<< num4 <<setw(16)<<right<< UnitPrice4 <<setw(20) <<right<< AmountofSale4<<endl<<endl;

cout<<"<5> Slices Of Pizza:"<<setw(5)<<left<< num5 <<setw(16)<<right<< UnitPrice5 <<setw(20) <<right<< AmountofSale5<<endl<<endl;

cout<<"<6> Super Salad:"<<setw(6)<<left<< num6 <<setw(16)<<right<< UnitPrice6 <<setw(22) <<right<< AmountofSale6<<endl<<endl;

cout<<"<7> Fountain Drink:"<<setw(6)<<left<< num7 <<setw(16)<<right<< UnitPrice7 <<setw(20) <<right<< AmountofSale7<<endl<<endl;

cout<<"<8> Green Tea:"<<setw(6)<<left<< num8 <<setw(16)<<right<< UnitPrice8 <<setw(25) <<right<< AmountofSale8<<endl<<endl;
}
              }

system("PAUSE");
return 0;
}


under default: (line 115), add: fflush(stdin);
Last edited on
That Didn't Seem To Fix It
maybe try std::cin.clear()
Topic archived. No new replies allowed.