i cant make it return to main choose after making ordering

Pages: 123
guys im having problem with the output ,when i make order it doesnt loop it at main choose do you have any sugesstion .seriously please help me
#include <iostream.h>
#include <stdlib.h>

void menu();
void F_order();
void pay();



struct queue
{
char kod[6];
struct queue *next;
};

struct queue *front = NULL;
struct queue *rear = NULL;


//global variable
int table_no,kod;

void main()
{
int choose;

cout<<"Enter your table number : ";
cin>>table_no;

do //supposeto loop here
{
cout<<"Choose a number\n";
cout<<"1=TO display menu\n";
cout<<"2=TO place customer order\n";
cout<<"3=TO diplay payment amount for customer order\n";
cout<<"4=Exit\n";


cin>>choose;



switch (choose)
{
case 1:
menu();
break;
case 2:
F_order();
break;

case 3:
pay();
break;

case 4:
exit(0);
break;
}

}
while (1);


}

void menu()
{

int move;

cout<<"What did your want to display?\n";
cout<<"1=Main dish\n";
cout<<"2=Desert\n";
cout<<"3=Drinks\n";
cout<<"4=Back to main menu\n";
cin>>move;

do
{

switch (move)
{
case 1:

cout<<"**************************************************\n";
cout<<"* KOD * FOOD NAME * PRICE *\n";
cout<<"**************************************************\n";
cout<<"* 001 * MIXED BENTO * RM 14 *\n";
cout<<"* 002 * CHEESE RING DAKGALBI * RM 10 *\n";
cout<<"* 003 * NYAM NYEON TONGDAK * RM 9 *\n";
cout<<"**************************************************\n";

break;

case 2:

cout<<"**************************************************\n";
cout<<"* KOD * DESSERT NAME * PRICE *\n";
cout<<"**************************************************\n";
cout<<"* 010 * FROZEN CARAMEL APPLE * RM 5 *\n";
cout<<"* 020 * BANANA SPLIT * RM 3 *\n";
cout<<"* 030 * CHERRY CREAM CHEESE * RM 5 *\n";
cout<<"**************************************************\n";

break;

case 3:

cout<<"**************************************************\n";
cout<<"* KOD * BEVERAGE NAME * PRICE *\n";
cout<<"**************************************************\n";
cout<<"* 100 * CHOCOLATE CREAM CHIPS * RM 6 *\n";
cout<<"* 200 * EXPRESSO MOCHA * RM 7 *\n";
cout<<"* 300 * BIG MILO TABUR * RM 5 *\n";
cout<<"**************************************************\n";

break;

case 4:
return;
break;

default:
cout<<"WRONG INPUT!!!\n";
break;

}

}

while (0);

}


void F_order()
{

struct queue *temp=NULL;
char choice;

do
{
temp= new queue;
cout<<"Enter food code\n";
cin>>temp->kod;
temp->next=NULL;
if(front==NULL)
{
front=temp;
}
else
{
rear->next=temp;
rear=temp;
}
cout<<"would you like to add more y/n?"<<endl;
cin>>choice;

}while (choice =='y');

cout<<"*******\n";
cout<<"* "<<temp->kod<<" *"<<endl;
cout<<"*******\n";


}

void pay()
{
int total=0,price,quantity,a;
char ans;

do
{

cout<<"Enter item amount\n";
cin>>a;

for (int i=1;i<=a;i++)
{
cout<<"Enter food price\n";
cin>>price;
cout<<"Enter food quantity\n";
cin>>quantity;

cout<<"Item amount="<<i<<endl;
total=total+(price * quantity);
cout<<"Total price = "<<total<<endl;

}

cout<<"Want to repeat?\n";
cout<<"Yes=y\n";
cout<<"No=n\n";
cin>>ans;
}
while(ans=='y'); //the problem occurs here
}
seriously why its crash again
Hello helena97,

I see three things to get you started that you can work on:

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

2. The header file "iostream.h" does not exist. Loose the ".h". If you are not familiar with header file anything that ends in ".h" is a C header file. C++ does not use file extensions for the standard header files. These days when I write a header file for a C++ program I use the extension ".hpp" to go with the ".cpp" extension for the code files.

3. You need to qualify "cout", "cin" and "endl" with "std::". Do not use the line using namespace std; This WILL get you in trouble some day. The search and replace will make this easier.

Something to work on while I dig into your program.

Hope that helps,

Andy
its bullshit andy.i try that and it got more error .
plus you dont even try it .you just keep judging it
Andy did (strongly) suggest that you edit your post with code tags. As is, your post is difficult to read.

Furthermore, he wrote (just minutes before your post):
Something to work on while I dig into your program.

Sounds like he "will be trying it", but working around the "irrelevant" things takes time.
Hi Helena.

You will find that insulting people who have something you want (in this case, knowledge) will make it less likely, rather than more likely, that they will help you.

You are very very bad at asking questions. This is going to be a big problem for you. The first way you are bad at asking questions is that you do not put your code in [code] tags [/code] , even though you have been asked to. You are making it difficult for people to read your code. Do you understand why that's a problem? It is insulting to them. You are making them do extra work to help you, a complete stranger. It is very impolite on your part.


You aren't fixing errors. You've been told before things that you keep doing.

void main() is wrong. Wrong wrong wrong. int main() is correct. You have been told this before, but we can all see that you are not fixing your code.

Why should we keep helping you if you don't accept our help?

Why should we keep helping you if you're going to insult us?

Your code crashes for the same reasons as before. Pointers that point to nothing. If you don't understand what we mean when we say that, then just say so. Just say "I am sorry; I don't understand what a pointer is, could you explain more simply please?" That's all you need to do.

Time for you to pick one. Grow up, start doing what we suggest, OR accept that you're not going to get this fixed and you're going to fail whatever class you're taking. This is your choice. Good luck.
Last edited on
Hello helena97,

its bullshit andy.i try that and it got more error .
plus you dont even try it .you just keep judging it


I have no patients for people who do not want to listen to what they are told. You only gave me 17 minutes to look into your code and that was not enough time to load the program, fix the errors and get it to compile before I could even test it.

I agree with Repeater your pointers point to nothing. It sounds like you have been told this before, so why should I cove what you already know.

Andy
@keskiverto @Repeater,

Thank you both for what you said.

Andy
Try and play around with 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <iostream>
#include <stdlib.h>

void menu();
void F_order();
void pay();



struct queue
{
	char kod[6];
	struct queue *next;
};

struct queue *front = NULL;
struct queue *rear = NULL;


//global variable
int table_no, kod;

using namespace std;

void main()
{
	do {
		int choose;
		bool stop = 1;
		cout << "Enter your table number : ";
		cin >> table_no;

		do //supposeto loop here
		{
			
			cout << "Choose a number\n";
			cout << "1=TO display menu\n";
			cout << "2=TO place customer order\n";
			cout << "3=TO display payment amount for customer order\n";
			cout << "4=Exit\n";


			cin >> choose;



			switch (choose)
			{
			case 1:
				menu();
				break;
			case 2:
				F_order();
				break;

			case 3:
				pay();
				break;

			case 4:
				stop = 0;
				break;
			}

		} while (stop);


		char done = ' ';
		cout << "Do you want to exit? y/n :";
			cin >> done;
		if (done == 'y' || done == 'Y') exit(0);
	} while (1);

}

void menu()
{

	int move;

	cout << "What did your want to display?\n";
	cout << "1=Main dish\n";
	cout << "2=Desert\n";
	cout << "3=Drinks\n";
	cout << "4=Back to main menu\n";
	cin >> move;

	

		switch (move)
		{
		case 1:

			cout << "**************************************************\n";
			cout << "* KOD * FOOD NAME * PRICE *\n";
			cout << "**************************************************\n";
			cout << "* 001 * MIXED BENTO * RM 14 *\n";
			cout << "* 002 * CHEESE RING DAKGALBI * RM 10 *\n";
			cout << "* 003 * NYAM NYEON TONGDAK * RM 9 *\n";
			cout << "**************************************************\n";

			break;

		case 2:

			cout << "**************************************************\n";
			cout << "* KOD * DESSERT NAME * PRICE *\n";
			cout << "**************************************************\n";
			cout << "* 010 * FROZEN CARAMEL APPLE * RM 5 *\n";
			cout << "* 020 * BANANA SPLIT * RM 3 *\n";
			cout << "* 030 * CHERRY CREAM CHEESE * RM 5 *\n";
			cout << "**************************************************\n";

			break;

		case 3:

			cout << "**************************************************\n";
			cout << "* KOD * BEVERAGE NAME * PRICE *\n";
			cout << "**************************************************\n";
			cout << "* 100 * CHOCOLATE CREAM CHIPS * RM 6 *\n";
			cout << "* 200 * EXPRESSO MOCHA * RM 7 *\n";
			cout << "* 300 * BIG MILO TABUR * RM 5 *\n";
			cout << "**************************************************\n";

			break;

		case 4:
			return;
			break;

		default:
			cout << "WRONG INPUT!!!\n";
			break;

		}

}


void F_order()
{

	struct queue *temp = NULL;
	char choice;

	do
	{
		temp = new queue;
		cout << "Enter food code\n";
		cin >> temp->kod;
		temp->next = NULL;
		if (front == NULL)
		{
			front = temp;
		}
		else
		{
			rear->next = temp;
			rear = temp;
		}
		cout << "would you like to add more y/n?" << endl;
		cin >> choice;

	} while (choice == 'y');

	cout << "*******\n";
	cout << "* " << temp->kod << " *" << endl;
	cout << "*******\n";


}

void pay()
{
	int total = 0, price, quantity, a;
	char ans;

	do
	{

		cout << "Enter item amount\n";
		cin >> a;

		for (int i = 1; i <= a; i++)
		{
			cout << "Enter food price\n";
			cin >> price;
			cout << "Enter food quantity\n";
			cin >> quantity;

			cout << "Item amount=" << i << endl;
			total = total + (price * quantity);
			cout << "Total price = " << total << endl;

		}

		cout << "Want to repeat?\n";
		cout << "Yes=y\n";
		cout << "No=n\n";
		cin >> ans;
	} while (ans == 'y'); //the problem occurs here
}
closed account (E0p9LyTq)
its bullshit andy.i try that and it got more error .
plus you dont even try it .you just keep judging it

I gather you wouldn't like to be informed your compiler or what your teacher is telling you is grossly outdated then.

In C++ it is not void main(). It is int main().

Cussing at people who are trying to help you is a mighty fine way to get ignored

Grab you some books, they won't mind being being cursed at.
Last edited on
im sorry andy , I was so stressed out about '.h' things
My lecturer told us to put '.h' and using namespace std; ,when you said.eliminate it ,I did ,but others said too put on it again. Im so.sorry to insult you guys that mostly experience about this.
Last edited on
if its getting stuck forever, try adding debugging lines. What I mean is, make the program output what it has in the variable that is being tested every time thru, so you can see it and figure out why the variable isn't what it's supposed to be.

sprinkle these cout statements anywhere you think they might help!
throw in a
cout << "\n" << ans << "\n"
after asking about ans, throw one in for numbers, etc etc .. you'll find out why the test is failing because you'll actually be able to see what's in the variables in your output. Sure, it'll make a mess of things, but you just remove or comment out those debugging lines after you're sure that part works.

It's funny how a lot of teachers will teach a programming class, but they never even bother to teach debugging at all. This leaves students skilled with only compiler output catching typos, but not being taught any skills to find actual coding errors. It's a horrible way to teach, and results in many frustrated students. I sympathize with you Helena.
zaphraud wrote:
if its getting stuck forever, try adding debugging lines. What I mean is, make the program output what it has in the variable that is being tested every time thru, so you can see it and figure out why the variable isn't what it's supposed to be.


Even better use a debugger, hopefully there is a GUI one in the IDE, other wise use a command line version. Set up a watch list of variables, step through the code 1 line at a time, see how the values change, deduce what went wrong. This has the advantages of not having to: Add output statements everywhere ; going back and deleting the output statements.
Last edited on
thanks those who help me out ,but the coding doesnt matter anymore . i stop studying programming .
We all struggle at first. And in my case, I still often struggle. But the only real failure is when we give up. Over used cliché I know...
It seems this course you were taking was crap.
Why do you want to give it up completely?
Why don't you try sth. simpler ?
http://mooc.fi/courses/2013/programming-part-1/
They have good course material + support channel
i dont know
What exactly you don't know?
Hello helena97,

I accept your apology, but as hard as it is to do yo managed to hurt my feelings and that takes longer to get over.

I tell you that "using namespace std;" is a bad idea and a problem and you say its "bullshit". To that I say load this program and compile it then tell what happens:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;

unsigned int count;

int main()
{
	count++;

	cout << "\n " << count << endl;

	return 0;
}


When you have done that put a comment on line 3 and "std::" in front of "cout" and "endl" and see what happens.

Let me know what you find out.

Andy
@Andy: s/count/cout/ ?
Pages: 123