반응형


앞서 자판기 프로그램을 파일입출력버전으로 만든 것 입니다.

굵은글씨부분을 추가하였습니다.^^


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
#include <stdio.h>
 
        int a,b,c,d,e,f =0;
        int aw,bw,cw,dw,ew,fw =0;
        int total=0;
        int start=0;
        int select=0;
        int save=0;
        int price=0;
        int choice=0;
        int hap=0;
        int won50000,won10000,won5000,won1000,won500,won100 = 0;
 
        struct stor{
        char name[10];
        char source[10];
        int price;
        int number;
        int plus;
        int make;
                };
        
        int main() 
        {
        
        struct stor s[5];
        int i;
        FILE *rfp;
        FILE *wfp;
 
        rfp=fopen("a.txt","r");
        wfp=fopen("b.txt","w");
 
        
 
        for(i=0;i<5;i++)
        {
        fscanf(rfp,"%s %s %d %d %d",&s[i].name, &s[i].source, &s[i].price, &s[i].number, &s[i].make);
        }
        fscanf(rfp,"%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
 
        fclose(rfp);
 
        /*
        for(i=0;i<5;i++)
        {
        printf("%s %s %d %d %d %d\n",s[i].name,s[i].source,s[i].price,s[i].number,s[i].plus,s[i].make);
        }
        return 0;
        */
 
         while(start==0)
            {
                  
 
                total = (a*50000)+(b*10000)+(c*5000)+(d*1000)+(e*500)+(f*100);
                printf("현재 총 %d원 있습니다.\n",total);
                printf("빵 판매를 시작해도 되겠습니까? ok = 1, no =0 \n");
                scanf("%d",&start);
            }
        
            while(start==1)
            {
                printf("시작합니다.\n");
                printf("1.빵고르기\n");
                printf("2.빵만들기\n");   
                printf("3.재료관리\n");
                printf("4.계산하기\n");
                printf("5.잔고관리\n");
                printf("6.종료하기\n"); 
                printf("7.전체보기\n"); 
                scanf("%d",&select);
                if(select==1)
                {
                    while(save!=6)
                    {
                     printf("빵을 골라주세요.\n");
                     printf("1.단팥빵\n");
                     printf("2.크림빵\n");
                     printf("3.옥수수빵\n");
                     printf("4.호두빵\n");
                     printf("5.초코빵\n");
                     printf("6.그만고르겠습니다.\n");
                     scanf("%d",&save);
                         switch(save)
                         {
                            case 1
                                if(s[0].number<=0)
                                    {
                                        printf("재고량이부족합니다. 만들어주세요\n");
                                        break;
                                    }
                                 price=price+s[0].price;
                                 s[0].number=s[0].number-1;
                                 break;
                            case 2:
                                if(s[1].number<=0)
                                    {
                                        printf("재고량이부족합니다. 만들어주세요\n");
                                        break;
                                    }
                                price=price+s[1].price;
                                s[1].number=s[1].number-1;
                               break;
                            case 3:
                                if(s[2].number<=0)
                                    {
                                        printf("재고량이부족합니다. 만들어주세요\n");
                                        break;
                                    }
                                price=price+s[2].price;
                                s[2].number=s[2].number-1;
                                break;
                            case 4:
                                if(s[3].number<=0)
                                    {
                                        printf("재고량이부족합니다. 만들어주세요\n");
                                        break;
                                    }
                                price=price+s[3].price;
                                s[3].number=s[3].number-1;
                                break;
                            case 5:
                                if(s[4].number<=0)
                                    {
                                        printf("재고량이부족합니다. 만들어주세요\n");
                                        break;
                                    }
                               price=price+s[4].price;
                               s[4].number=s[4].number-1;
                               break;
                            case 6:
                                break;
                            default:
                               printf("잘못입력하셨습니다.\n");
                               select = 0;
                               break;
                        }//switch
                    }//while    
                save=0;
                }//if
                else if(select==2)
                    {
                        while(select==2)
                            {
                                printf("빵만들기를시작합니다.\n");
                                printf("무슨빵을 만드시겠습니까? \n");
                                printf("1.단팥빵\n");
                                printf("2.크림빵\n");
                                printf("3.옥수수빵\n");
                                printf("4.호두빵\n");
                                printf("5.초코빵\n");
                                printf("6.빵만들기종료\n");
                                scanf("%d",&choice);
                                if (choice==1)
                                    {
                                        if(s[0].make<=0)
                                            {
                                                printf("재료재고량이 부족합니다.\n");
                                                break;
                                            }
                                        s[0].make=s[0].make-1;
                                        s[0].number=s[0].number+1;
                                        printf("단팥의 갯수는 %d입니다.\n",s[0].make);
                                        printf("단팥빵의 갯수는 %d입니다.\n",s[0].number);
                                    }
                                else if( choice==2)
                                    {
                                        if(s[1].make<=0)
                                            {
                                               printf("재료재고량이 부족합니다.\n");
                                               break;
                                            }
                                       s[1].make=s[1].make-1;
                                       s[1].number=s[1].number+1;
                                       printf("크림의 갯수는 %d입니다.\n",s[1].make);
                                       printf("크림빵의 갯수는 %d입니다.\n",s[1].number);
                                    }
                                else if( choice==3)
                                    {
                                        if(s[2].make<=0)
                                            {
                                               printf("재료재고량이 부족합니다.\n");
                                               break;
                                            }
                                       s[2].make=s[2].make-1;
                                       s[2].number=s[2].number+1;
                                       printf("옥수수의 갯수는 %d입니다.\n",s[2].make);
                                       printf("옥수수빵의 갯수는 %d입니다.\n",s[2].number);
                                    }
                                else if( choice==4)
                                    {
                                        if(s[3].make<=0)
                                            {
                                               printf("재료재고량이 부족합니다.\n");
                                               break;
                                            }
                                       s[3].make=s[3].make-1;
                                       s[3].number=s[3].number+1;
                                       printf("호두의 갯수는 %d입니다.\n",s[3].make);
                                       printf("호두빵의 갯수는 %d입니다.\n",s[3].number);
                                    }
                                else if( choice==5)
                                    {
                                        if(s[4].make<=0)
                                            {
                                               printf("재료재고량이 부족합니다.\n");
                                               break;
                                            }
                                       s[4].number=s[4].number+1;
                                       s[4].make=s[4].make-1;
                                       printf("초코의 갯수는 %d입니다.\n",s[4].make);
                                       printf("초코빵의 갯수는 %d입니다.\n",s[4].number);
                                    }
                                else if( choice==6)
                                    {
                                       break;
                                    }
                                else
                                    {
                                       printf("잘못입력하셨습니다.\n");
                                       break;
                                    }
                            }//while
                    }//else if
                else if(select==3)
                    {
                        printf("재료관리를 시작합니다.\n");
                            for(i=0;i<5;i++)
                                {
                                     printf("%s 는 몇개 추가하시겠습니까?: ",s[i].source);
                                     scanf("%d",&s[i].plus);
                                     s[i].make=s[i].make+s[i].plus;
                                }
                    }
                else if(select==4)
                    {
                        printf("계산합니다.\n");
                        printf("총 %d 원 입니다. \n",price);
                        printf("50000,10000,5000,1000,500,100순으로 받은갯수를 입력하세요.\n");
                        scanf("%d",&aw);
                        scanf("%d",&bw);
                        scanf("%d",&cw);
                        scanf("%d",&dw);
                        scanf("%d",&ew);
                        scanf("%d",&fw);
                        hap=50000*aw + 10000*bw + 5000*cw + 1000*dw +500*ew + 100*fw;
                        printf("총 %d받았습니다.\n",hap);
                            if(hap<price)
                                {
                                    printf("%d원 더 내주세요.\n",price-hap);
                                }
                            if(price<=hap)
                                {
                                    printf("%d 거슬러 드리겠습니다.\n",hap-price);
                                    a=a+aw;
                                    b=b+bw;
                                    c=c+cw;
                                    d=d+dw;
                                    e=e+ew;
                                    f=f+fw;
                                    won50000=(hap-price)/50000;
                                    won10000=((hap-price)%50000)/10000;
                                    won5000=(((hap-price)%50000)%10000)/5000;
                                    won1000=((((hap-price)%50000)%10000)%5000)/1000;
                                    won500=(((((hap-price)%50000)%10000)%5000)%1000)/500;
                                    won100=((((((hap-price)%50000)%10000)%5000)%1000)%500)/100;
                                    a=a-won50000;
                                    b=b-won10000;
                                    c=c-won5000;
                                    d=d-won1000;
                                    e=e-won500;
                                    f=f-won100;
                                        if(a<0||b<0||c<0||d<0||e<0||f<0)
                                            {
                                                printf("잔고가부족합니다.\n");
                                            if(a<0)
                                                {
                                                    printf("50000원권 갯수부족합니다.\n");
                                                }
                                            if(b<0)
                                                {
                                                   printf("10000원권 갯수부족합니다.\n");
                                                }
                                            if(c<0)
                                                {
                                                   printf("5000원권 갯수부족합니다.\n");
                                                }
                                             if(d<0)
                                                {
                                                   printf("1000원권 갯수부족합니다.\n");
                                                }
                                            if(e<0)
                                                {
                                                   printf("500원권 갯수부족합니다.\n");
                                                }
                                            if(f<0)
                                                {
                                                   printf("100원권 갯수부족합니다.\n");
                                                }
                                             a=a-aw;
                                             b=b-bw;
                                             c=c-cw;
                                             d=d-dw;
                                             e=e-ew;
                                             f=f-fw;
                                             a=a+won50000;
                                             b=b+won10000;
                                             c=c+won5000;
                                             d=d+won1000;
                                             e=e+won500;
                                             f=f+won100;
                                            }//if
                                        else
                                            {
                                            printf("고객에게 내어줄 잔돈은 다음과 같습니다.\n");
                                            printf("오만원권 : %d 매\n",won50000);
                                            printf("만원권 : %d 매\n",won10000);
                                            printf("오천원권 : %d 매\n",won5000);
                                            printf("천원권 : %d 매\n",won1000);
                                            printf("오백원 : %d 매\n",won500);
                                            printf("백원 : %d 매\n",won100);
                                            price=0;
                                            }
                            }//if
                    }//else if
                else if(select==5)
                    {
                        printf("잔고관리를시작합니다.\n");
                        printf("오만원권 : %d 매\n",a);
                        printf("만원권 : %d 매\n",b);
                        printf("오천원권 : %d 매\n",c);
                        printf("천원권 : %d 매\n",d);
                        printf("오백원 : %d 매\n",e);
                        printf("백원 : %d 매\n",f);
                    }
                else if(select==6)
                    {
                        printf("프로그램종료.\n");
                        start = 0;
                        break;
                    }
                else
                    {
                        printf("잘못입력하셨습니다.\n");
                    }
            }//while
 
            fprintf(wfp,"빵이름, 재료이름, 가격, 빵갯수, 재료재고량\n");
            for(i=0;i<5;i++)
            {
            fprintf(wfp,"%s    %s    %d    %d    %d\n",s[i].name,s[i].source,s[i].price,s[i].number,s[i].make);
            }
            fprintf(wfp,"오만원 : %d매//  만원 : %d매  // 오천원 : %d매 // 천원 : %d매 // 오백원 : %d개 // 백원 : %d개\n",a,b,c,d,e,f);
            fprintf(wfp,"오늘의 총 수입은 %d원입니다",((50000*a)+(10000*b)+(5000*c)+(1000*d)+(500*e)+(100*f))-total);
        }//main
cs






visual studio의 프로젝트 안에 a라는 파일에 아래와 같이 글자와 숫자를 입력해 놓으면





b라는 파일이름으로 아래와 같이 파일에 입력되어 나타납니다.










반응형

+ Recent posts