게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
Vending[자판기] 프로그램 개선
게시물ID : programmer_20248짧은주소 복사하기
작성자 : Simmons
추천 : 0
조회수 : 413회
댓글수 : 5개
등록시간 : 2017/04/10 09:24:10
옵션
  • 창작글
  • 베스트금지
  • 베오베금지
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
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
 
int show_list();
int input_money();
int input_choice();
int choice_money(int choice, int money, int add_money);
 
 
 
int main()
{
    int choice = 0;
    int money = 0;
    int add_money = 0;
 
    show_list();
    money = input_money();
    choice = input_choice();
    
    choice_money(choice, money, add_money);
}
 
int show_list()
{
    printf("1. Cola\t\t800won\n");
    printf("2. Orange\t800won\n");
    printf("3. Mountain\t1000won\n");
    printf("4. Americano\t1500won\n");
    printf("5. Strawberry\t2000won\n\n");
 
    return 0;
}
int input_money()
{
    int money = 0;
    printf("Put the money:");
    scanf_s("%d"&money);
    return money;
}
 
int input_choice()
{
    int choice = 0;
    printf("choice beverage:");
    scanf_s("%d"&choice);
    return choice;
}
 
int choice_money(int choice, int money, int add_money) {
    int result = 0;
 
    if (choice == 1) {
        if (800 > money) {
            printf("Lack of money.\n");
 
            int num = 0;
 
            while (1) {
                printf("Amount required : %d\n"800 - money);
                num++;
                printf("Put the money:");
                scanf("%d"&add_money);
 
                money = add_money + money;
                result = money;
 
                printf("Now money : %d\n", money);
                
                if (money >= 800) {
                    printf("Cola\n");
                    result = money - 800;
                    printf("Remainder Money: %d\n", result);
                }
 
                if (money >= 800)
                    break;
            }
 
        }
        else {
            printf("Cola\n");
            result = money - 800;
            printf("Remainder Money: %d\n", result);
        }
    }
 
    else if (choice == 2) {
        if (800 > money) {
            printf("Lack of money.\n");
 
            int num = 0;
 
            while (1) {
                printf("Amount required : %d\n"800 - money);
                num++;
                printf("Put the money:");
                scanf("%d"&add_money);
 
                money = add_money + money;
                result = money;
 
                printf("Now money : %d\n", money);
 
                if (money >= 800) {
                    printf("Orange\n");
                    result = money - 800;
                    printf("Remainder Money: %d\n", result);
                }
 
                if (money >= 800)
                    break;
            }
 
        }
        else {
            printf("Orange\n");
            result = money - 800;
        }
    }
 
    else if (choice == 3) {
        if (1000 > money) {
            printf("Lack of money.\n");
 
            int num = 0;
 
            while (1) {
                printf("Amount required : %d\n"1000 - money);
                num++;
                printf("Put the money:");
                scanf("%d"&add_money);
 
                money = add_money + money;
                result = money;
 
                printf("Now money : %d\n", money);
 
                if (money >= 1000) {
                    printf("Mountain\n");
                    result = money - 1000;
                    printf("Remainder Money: %d\n", result);
                }
 
                if (money >= 1000)
                    break;
            }
 
        }
 
        else {
            printf("Mountain\n");
            result = money - 1000;
        }
    }
 
    else if (choice == 4) {
        if (1500 > money) {
            printf("Lack of money.\n");
 
            int num = 0;
 
            while (1) {
                printf("Amount required : %d\n"1500 - money);
                num++;
                printf("Put the money:");
                scanf("%d"&add_money);
 
                money = add_money + money;
                result = money;
 
                printf("Now money : %d\n", money);
 
                if (money >= 1500) {
                    printf("Americano\n");
                    result = money - 1500;
                    printf("Remainder Money: %d\n", result);
                }
 
                if (money >= 1500)
                    break;
            }
 
        }
        else {
            printf("Strawberry");
            result = money - 1500;
        }
    }
 
    else if (choice == 5) {
        if (2000 > money) {
            printf("Lack of money.\n");
 
            int num = 0;
 
            while (1) {
                printf("Amount required : %d\n"2000 - money);
                num++;
                printf("Put the money:");
                scanf("%d"&add_money);
 
                money = add_money + money;
                result = money;
 
                printf("Now money : %d\n", money);
 
                if (money >= 2000) {
                    printf("Strawberry\n");
                    result = money - 2000;
                    printf("Remainder Money: %d\n", result);
                }
 
                if (money >= 2000)
                    break;
            }
 
        }
        else {
            printf("Strawberry");
            result = money - 2000;
        }
    }
    return result;
 
}
cs

2일정도 걸려서 몇번 막히고 그때마다 물어보고 싶었지만 참고 해결방법을 계속 찾는 과정에서 드디어 완성을 시켰습니다.
혹시 개선하고싶은 부분이나 이부분은 이걸 쓰면 안되는데 이걸 썻으니 다른걸 쓰면 좋겠다 라는점 있을까요? 
코딩을 집에서 혼자 하다보니 우물 안 개구리가 되어서 여러분의 도움이 필요합니다 ㅠ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호