i cant make it return to main choose after making ordering

Pages: 123
Hello helena97,

Yes you could do that, but the entire file would have access to those variables and when one of the functions changes one of those variables it could take hours trying to figure out which function is causing the problem.

It is best to stay away from global variables unless there are constant variables that can not be changed.

In the last year I have found that it is better to define the variables in main and pass them to the functions that need them. If you intend to change a variables value then pass by reference. Other variables are defined in the functions that would use them and they are destroyed when the function ends. That is why you an use the same variable name in a function without any conflict because it is local to the function.

I point to the example where I defined the "price" array in main and passed it to the "f_order" function. Should it be needed in another function all that is needed is to pass it.

Hope that helps,

Andy
good point .thank you for suggested coding ,and im sorry burdening you with my problem .im so sorry i wasnt respect you and i really wish i could do something to take it back.

and i will try the code that you suggested .

thanks andy
Hello helena97,

I was just reading through this: http://www.cplusplus.com/forum/beginner/233706/ and thought the concept might help you. The programming part is not the point, but how it starts out.

It is not a burden and as it is said "the rest is water under the bridge".

If I had the chance to start over with this program I would use a vector of structs and not a linked list as the vector is much easier to use.

Next time you have a program to write start early before you try to fix what should not have been written in the first place. Also the more you plan the program the less time it takes to code because you can work out most problems before you start coding.

Catch me early and I can be there for guidance from the start.

Andy
ermmm andy i got reject again so this is my new code.im having problem with data type ,

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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include <iostream.h>
#include <stdlib.h>

void menu();
void F_order();
void pay();
void display();
void D_base();

//global variable
int table_no,kod,total,total_amount,Price;
char Kod[6],f_name[30];

struct node
{   
	char kod[6],F_name[30];
	int price,quantity;
	struct node * next;
};

struct node * head=NULL;
struct node * tail=NULL;

void D_base()
{
	int code,Price,Quantity;
	char kod,f_name;

	cout<<"Enter food code\n";
	cout<<"1=001\n2=002\n3=003\n4=010\n5=020\n6=030\n7=100\n8=200\n9=300\n";
	cin>>code;

	switch (code)
	{
	case 1:

		Kod='001';
		f_name='Mixed Bento';
		Price=20;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;
	
	case 2:

		Kod='002';
		f_name='Cheese Ring Dakgalbi';
		Price=30;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 3:
		Kod='003';
		f_name='Nyam Nyeon Tongdak';
		Price=15;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 4:

		Kod='010';
		F_name='Frozen Caramel Apple';
		Price=10;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 5:

		Kod='020';
		f_name='Banana Split';
		Price=5;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 6:

		Kod='030';
		f_name='Cherry Cream Cheese';
		Price=10;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 7:

		Kod='100';
		f_name='Chocolate Cream Chip';
		Price=20;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 8:
		Kod='200';
		f_name='Expresso Mocha';
		Price=10;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 9:

		Kod='300';
		f_name='Big Milo Tabur';
		Price=5;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;
	
	}

}

void F_order(char Kod,char f_name,int Price,char Quantity)
{
	struct node * temp;
	temp=new node;

	temp->kod=Kod;
	temp->F_name=f_name;
	temp->price=Price;

	temp->next=NULL;

	if(head==NULL)
	{
		head=temp;
		tail=head;
	}
	else
	{
		tail->next=temp;
		tail=temp;
		tail->next=NULL;
	}

}

void pay()
{
	int Quantity,Price;

	total=Price*Quantity;
	total_amount=total_amount+total;


}

void display()
{
	if(head==NULL)
	{
		cout<<"No order\n";
	}
	else
	{
		struct node *temp=head;

		while(temp->next!=NULL)
		{
			cout<<"THE CODE IS"<<temp->kod;
			cout<<"THE FOOD NAME IS"<<temp->F_name;
			cout<<"THE PRICE IS"<<temp->price;
		}
	}

	cout<<total_amount<<endl;
}


void main()
{
	int choose;

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

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

	cin>>choose;

	cout<<"\n"<<endl;



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

	case 2:
		F_order();
	break;

	case 3:
		display();
	break;

	case 4:
		pay();
	break;

	case 5:
		exit(0);
	break;
	}

	}
	while (1);


}


still have error in it ,i try to fix it
Last edited on
The compiler error messages should contain line numbers.

1
2
Kod = '001';
f_name = 'Mixed Bento';

One does put single character into single quotes. For example: 'x' or '\n'. The \n is way to write one character, the newline character.

'001' is not one character. Neither is 'Mixed Bento'.

I guess you mean C-strings, aka null-terminated arrays of characters, i.e. words/text. Those require double quotes: "001" and "Mixed Bento"


Alas, there is no assignment operator from array of characters to array of characters. The C Library has C-string copy functions.


You say on line 5: void F_order();
That is: "name 'F_order' belongs to a function that does not take any arguments and does not return a value".

On line 172 is a different function that also has name 'F_order', but it takes four arguments.

The declaration on line 5 must match the implementation on line 172.
so i have to change the data type from char to string??

1
2
Kod = "001\n";
f_name = "Mixed Bento\n";
Last edited on
@helena97 -- it's not a single char; it's an array of characters. How are you testing this if it's not even compiling? You'd do well to do a massive find+replace of ' with " from your latest. Also you're not applying any changes that have been suggested, e.g. #include <iostream> -- there is no iostream.h
Last edited on
closed account (E0p9LyTq)
Thread duplication:
http://www.cplusplus.com/forum/beginner/234053/
dear icy,
i try string too
this is it

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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include <iostream>
#include <cstdlib>
#include <cstring>

void menu();
void F_order();
void pay();
void display();
void D_base();

//global variable
int table_no,total,total_amount,Price,Quantity;
string Kod[6],f_name[30],kod[6],F_name[30];

struct node
{   
	string kod[6],F_name[30];
	int price,quantity;
	struct node * next;
};

struct node * head=NULL;
struct node * tail=NULL;

void D_base()
{
	int code;

	cout<<"Enter food code\n";
	cout<<"1=001\n2=002\n3=003\n4=010\n5=020\n6=030\n7=100\n8=200\n9=300\n";
	cin>>code;

	switch (code)
	{
	case 1:

		Kod="001";
		f_name="Mixed Bento";
		Price=20;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;
	
	case 2:

		Kod="002";
		f_name="Cheese Ring Dakgalbi";
		Price=30;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 3:
		Kod="003";
		f_name="Nyam Nyeon Tongdak";
		Price=15;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 4:

		Kod="010";
		F_name="Frozen Caramel Apple";
		Price=10;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 5:

		Kod="020";
		f_name="Banana Split";
		Price=5;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 6:

		Kod="030";
		f_name="Cherry Cream Cheese";
		Price=10;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 7:

		Kod="100";
		f_name="Chocolate Cream Chip";
		Price=20;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 8:
		Kod="200";
		f_name="Expresso Mocha";
		Price=10;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;

	case 9:

		Kod="300";
		f_name="Big Milo Tabur";
		Price=5;

		cout<<"Enter quantity\n";
		cin>>Quantity;

		F_order(Kod,f_name,Price,Quantity);

		pay(Price,Quantity);

	break;
	
	}

}

void F_order(string Kod,string f_name,int Price,char Quantity)
{
	struct node * temp;
	temp=new node;

	temp->kod=Kod;
	temp->F_name=f_name;
	temp->price=Price;

	temp->next=NULL;

	if(head==NULL)
	{
		head=temp;
		tail=head;
	}
	else
	{
		tail->next=temp;
		tail=temp;
		tail->next=NULL;
	}

}

void pay()
{
	total=Price*Quantity;
	total_amount=total_amount+total;


}

void display()
{
	if(head==NULL)
	{
		cout<<"No order\n";
	}
	else
	{
		struct node *temp=head;

		while(temp->next!=NULL)
		{
			cout<<"THE CODE IS"<<temp->kod;
			cout<<"THE FOOD NAME IS"<<temp->F_name;
			cout<<"THE PRICE IS"<<temp->price;
		}
	}

	cout<<total_amount<<endl;
}


void main()
{
	int choose;

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

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

	cin>>choose;

	cout<<"\n"<<endl;



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

	case 2:
		F_order();
	break;

	case 3:
		display();
	break;

	case 4:
		pay();
	break;

	case 5:
		exit(0);
	break;
	}

	}
	while (1);


}

errors
1
2
3
4
5
6
7
project20juta.cpp
C:\Users\user\Desktop\spartan\spartan c++\project20juta.cpp(13) : error C2146: syntax error : missing ';' before identifier 'Kod'
C:\Users\user\Desktop\spartan\spartan c++\project20juta.cpp(13) : error C2501: 'string' : missing storage-class or type specifiers
C:\Users\user\Desktop\spartan\spartan c++\project20juta.cpp(13) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

project20juta.exe - 3 error(s), 0 warning(s)

Hello helena97,

To start with, what IDE/compiler are you using?

When I loaded up your last code I found that "string", "cin", "cout" and "endl" all need to be qualified and start with "std::". After fixing that I did get the errors down to 114.

If what you want is to use the STL "std::string" then you will need to include the header file "<string>". I believe you will find it better to use than "cstring" which just wraps the "string.h" header file in the standard name space.

On line 13 you define global variables. Not the best idea as you define "kod" here then again online 17 in the struct. This could be a potential problem later in the program.

On lines 13 and 17 you define your variables as arrays. I hope you are not thinking of these a C style character arrays, because they are not. Each element of the array is a "std::string" which in its self is an array at its base.

My next error is at lines 37 and 38. "Kod" and "f_name" are arrays. The problem here is that the compiler does not know which element of the array to store the information in.

Line 44 my error says that what is being passed or received by the function do not match. In this case the function definition is incorrect.

Even though your functions are above main does not mean you are problem free. Since the compiler works from top to bottom some functions are being called before the compiler sees them. Even with the functions above main order is important or better put prototypes above the functions. Prototypes would be the quickest and easiest way to solve the problem.

Line 44 is sending "Kod" to the function, but the function is expecting a single variable not the array you are sending. The function definition needs to reflect that the variable coming in is an array. And here the prototype and function definition need to match.

before I put any more time into this version I need to look at the last version and even compare the two.

Something to think about and work on if you want for now until I here why th last one failed.

Hope that helps,

Andy
Topic archived. No new replies allowed.
Pages: 123