Help me please!!

I can't do the edit, delete and the transaction. something have problem in my view function i need help

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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
 #include<iostream>
#include<cstdlib>
#include<string.h>
#include<fstream>
#include<iostream>
#include<conio.h>

using namespace std;

void addrecord();
void editrecord();
void viewrecord();
void deleterecord();
void transaction();
string employee;
string customer; 
string product;
double empcode;

int main(int argc, char*argv[]){


    int choice;
    while (choice !=0){
          system("cls");
      system("color 03");
    cout<<"***Main Window***"<<endl;
    cout<<"1.Add Record"<<endl;
    cout<<"2.Edit Record"<<endl;
    cout<<"3.View Record"<<endl;
    cout<<"4.Delete Record"<<endl;
    cout<<"5.Transaction"<<endl;
    cout<<"0.Exit"<<endl;
    cout<<"Enter your choice:";
    cin>>choice;
    if (choice>5 || choice<0) return 0;
    else
    switch (choice){
           case 1:addrecord();
           break;
           case 2:editrecord();
           break;
           case 3:viewrecord();
           break;
           case 4:deleterecord();
           break;
      
           system("PAUSE");
           return EXIT_SUCCESS;
           
}}}
                  
void addrecord(){


     string empcode,fname,pos,bpay,cuscode,emprecord;
     int choice;
     string cat;
     int connum;
     string procode;
     string d;
     int p;
    
    while (choice !=0){
             system("cls");
    if (choice==1)
    cout<<"***Add Record***"<<endl;
    cout<<"1.Employee"<<endl;
    cout<<"2.Customer"<<endl;
    cout<<"3.Product"<<endl;
    cout<<"0.Back to Main Window"<<endl;
    cout<<"Enter your choice:";
    cin>>choice;
    
    if (choice==1){
    
    switch (choice){
           case 1:employee;
       system("cls");
    cout<<"1.Employee Code:";
    cin>>empcode;
    cout<<"Fullname:";
    getline(cin,fname);
    getline(cin,fname);
    cout<<"Position:";
    getline(cin,pos);
    cout<<"Basic Pay:";
    getline(cin,bpay);
           ofstream newemp;
newemp.open("emprecord.txt",ios::app);
if (newemp.is_open())
newemp<<empcode<<","<<fname<<","<<pos<<","<<bpay<<endl;
else{
cout<<"Error! Writing to a file failed.";
exit(1);}
newemp.close();
           break;}}


           
    if (choice==2){
    
    switch (choice){
           case 2:customer;
       system("cls");
    cout<<"1.Customer Code:";
    cin>>cuscode;
    cout<<"Fullname:";
    getline(cin,fname);
    getline(cin,fname);
    cout<<"Category:";
    cin>>cat;
    cout<<"Contact Number:";
    cin>>connum;
           ofstream newcus;
newcus.open("cusrecord.txt",ios::app);
if (newcus.is_open())
newcus<<cuscode<<","<<fname<<","<<cat<<","<<connum<<endl;
else{
cout<<"Error! Writing to a file failed.";
exit(1);}
newcus.close();
           break;}}

    if (choice==3){
    
    switch (choice){
           case 3:product;
       system("cls");
    cout<<"1.Product Code:";
    cin>>procode;
    cout<<"Description:";
    getline(cin,d);
    getline(cin,d);
    cout<<"Price:";
    cin>>p;
           ofstream newpro;
newpro.open("prorecord.txt",ios::app);
if (newpro.is_open())
newpro<<procode<<","<<d<<","<<p<<endl;
else{
cout<<"Error! Writing to a file failed.";
exit(1);}
newpro.close();
           break;}}
           
}system("pause");}


void editrecord(){
           ofstream newemp;
             	    newemp.open("emprecord.txt");
     string empcode,fname,pos,bpay,cuscode;
     int choice;
     string cat;
     int connum;
     string procode;
     string d;
     int p;
    
    while (choice !=0){
             system("cls");
    if (choice==2)  
    cout<<"***Edit Record***"<<endl;
    cout<<"1.Employee"<<endl;
    cout<<"2.Customer"<<endl;
    cout<<"3.Product"<<endl;
    cout<<"0.Back to Main Window"<<endl;
    cout<<"Enter your choice:";
    cin>>choice;
    if (choice==1){

       system("cls");
    cout<<"1.Employee Code:";
    cin>>empcode;

           ifstream eeditrecord;

           eeditrecord.open("emprecord.txt");
	        while (!eeditrecord.eof() && employee!=empcode)

	 
	 
	        cout<<"Fullname: "<<endl;
	        cin>>fname;
	 
	        cout<<"Position:"<<endl;
	        cin>>p;
	 
	        cout<<"Basic Pay:"<<endl;
	        cin>>bpay;
	 
	        newemp<<fname<<endl;
	        newemp<<pos<<endl;
	        newemp<<bpay<<endl<<endl<<endl;
	 
	       
	 
	    }           
        if (choice==2)
    switch (choice){
           
           case 2:customer;
           system("cls");
    cout<<"2.Customer Code:";
    cin>>cuscode;
    cout<<"Fullname:";
    cin>>fname;
    cout<<"Category:";
    cin>>cat;
    cout<<"Contact number:";
    cin>>connum;
           break;}
           
    if (choice==3)
    switch (choice){
           
           case 3:product;
           system("cls");
    cout<<"3.Product Code:";
    cin>>procode;
    cout<<"Description:";
    cin>>d;
    cout<<"Price:";
    cin>>p; 
           break;}
    
}}
   
void viewrecord(){
 
    int choice;
    

    string empcode,empname,pos, bpay;
    string cuscode,cusname,cat,connum;
    string procode,d,p;

    system("cls");
    cout<<"***View Record***"<<endl;
    cout<<"1.Employee"<<endl;
    cout<<"2.Customer"<<endl;
    cout<<"3.Product"<<endl;
    cout<<"0.Back to main window"<<endl;
    cout<<"Enter your choice:";
    cin>>choice;
    if (choice==1){
           system("cls");   
cout<<"Employee Code:";
cin>>empcode;
system("cls");

ifstream ereadrec;
ereadrec.open("emprecord.txt");
while(!ereadrec.eof() && ereadrec != '\0')

ereadrec>>empcode;
ereadrec>>empname;
ereadrec>>pos;
ereadrec>>bpay;


if( empcode == empcode)
{
cout<<"*************************************"<<endl; 
cout << "Employee Code : ";
cout << empcode<<endl;
cout << "Fullname : ";
cout << empname<<endl;
cout << "Position : ";
cout << pos<<endl;
cout << "Basic Pay : ";
cout << bpay<<endl;}}
cout<<"*************************************"<<endl;

                             
                          
      if (choice==2){
    

           system("cls");   
cout<<"Customer Code:";
cin>>cuscode;
system("cls");

ifstream creadrec;
creadrec.open("cusrecord.txt");
while(!creadrec.eof() && creadrec != '\0')
creadrec >>cuscode;
creadrec >>cusname;
creadrec >>cat;
creadrec >>connum;



if( cuscode == cuscode)
{cout<<"*************************************"<<endl; 
cout << "Customer Code : ";
cout << cuscode<<endl;
cout << "Fullname : ";
cout << cusname<<endl;
cout << "Category : ";
cout << cat<<endl;
cout << "Contact Number : ";
cout << connum<<endl;}}
cout<<"*************************************"<<endl;

     
    
      if (choice==3){

           system("cls");   
cout<<"Product Code:";
cin>>procode;
system("cls");

ifstream preadrec;
preadrec.open("prorecord.txt");
while(!preadrec.eof() && preadrec != '\0')

preadrec >>procode;
preadrec >>d;
preadrec >>p;


if( procode == procode)
{cout<<"*************************************"<<endl; 
cout << "Product Code : ";
cout << procode<<endl;
cout << "Description : ";
cout << d<<endl;
cout << "Price : ";
cout << p<<endl;

}}cout<<"*************************************"<<endl;   
system("pause");}







void deleterecord()
 {
   
int temp_empcode;
int temp_cuscode;
int temp_procode;
int choice;
system("cls");
    cout<<"***Delete Record***"<<endl;
    cout<<"1.Employee"<<endl;
    cout<<"2.Customer"<<endl;
    cout<<"3.Product"<<endl;
    cout<<"0.Back to main window"<<endl;
    cout<<"Enter your choice:";
    cin>>choice;
    system("cls");
    if (choice==1)
    switch(choice){
                   case 1: employee;
                   cout<<"Enter employee code to be deleted: ";
                   cin>>temp_empcode;
                   break;}


    system("cls");
    if (choice==2)
    switch(choice){
                   case 2: customer;
                   cout<<"Enter customer code to be deleted: ";
                   cin>>temp_cuscode;
                   break;}  
    system("cls");
    if (choice==3)
    switch(choice){
                   case 3: product;
                   cout<<"Enter product code to be deleted: ";
                   cin>>temp_procode;
                   break;}
                     

}
where do we even begin,

so many mistakes here I would almost say do a total rewrite.

but to name some, in your functions you declare a variable and assign no value to it but then check to see its value? This would create an error, but it does not matter anyways since your void functions take no referenced variables so they do nothing. But that does not matter since you have no objects to store the data in.

I would suggest you break your program down to one function at a time. Get just one to work before moving on to the next.

Good luck :)
Last edited on
Topic archived. No new replies allowed.