May 28, 2014 at 6:48pm UTC
I have been working on this for long, I can get it working, but I need to use a letter to exit, am sure am missing something, please point me on the right track. Thanks.
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
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int item_Number;
char E;
repeat:
cout << "Please enter the item number starting from number 20 increasing by 10" <<endl;
cin >> item_Number;
if (item_Number == 20)
cout << "Apples" << endl;
else if (item_Number == 30)
cout << "Cereal" << endl;
else if (item_Number == 40)
cout << "Popcorn" << endl;
else if (item_Number == 50)
cout << "Bread" << endl;
else if (item_Number == 60)
cout << "Cookie" << endl;
else if (item_Number == 70)
cout << "Water" << endl;
else
cout << "Item not in the inventory, try again!" << endl;
cout << "To exit input 'E'" << endl;
goto repeat;
cin >> E;
if (E == E)
break ;
return 0;
}
Last edited on May 28, 2014 at 6:48pm UTC
May 28, 2014 at 6:52pm UTC
You need to replace
1 2 3 4 5
repeat:
...
goto repeat;
cin >> E;
if (E == E)
with
1 2 3 4
do {
...
cin >> E;
} while (E != 'E' );
Also, consider changing the variable E to something like exitChar to make the meaning clearer.
Note that E is a variable and 'E' is a character constant.
Last edited on May 28, 2014 at 8:04pm UTC
May 28, 2014 at 7:14pm UTC
I tried, not sure do{
...
May 28, 2014 at 7:47pm UTC
42 43 44 45
cin >> E;
if (E != 'E' )
goto repeat;
return 0;
Last edited on May 28, 2014 at 7:47pm UTC
May 28, 2014 at 7:52pm UTC
you should delete line 42, because when you write goto then your program didn't check is value of 'E' equals to "E" or not! so you should wrote the goto after break on line 45
Have Nice Life