-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.c
85 lines (78 loc) · 1.87 KB
/
a.c
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
#include <stdio.h>
#include <string.h>
typedef struct{
int id;
int balance;
char name[20];
} account;
account accArr[100];
int accNum=0;
int showmenu(){
printf("\n");
printf("1. 계좌개설\n2. 입금\n3. 출금\n4. 계좌출력\n5. 종료\n");
}
int make(){
printf("계좌번호: ");
scanf("%d", &accArr[accNum].id);
printf("이름: ");
scanf("%s", &accArr[accNum].name);
printf("입금액 : ");
scanf("%d", &accArr[accNum].balance);
accNum++;
}
int deposit(){
int acc, dep,i ;
printf("\n");
printf("입금할 계좌 : ");
scanf("%d",&acc);
printf("입금할 금액 : ");
scanf("%d",&dep);
for (i = 0; i < accNum; i++) if(acc==accArr[i].id) accArr[i].balance += dep;
}
int withdraw(){
int acc,wd,i ;
printf("\n");
printf("출금할 계좌 : ");
scanf("%d",&acc);
printf("출금할 금액 : ");
scanf("%d",&wd);
for (i = 0; i < accNum; i++) {
if(acc==accArr[i].id) {
if (accArr[i].balance<wd)
{
printf("잔액이 부족합니다.\n");
}else
{
accArr[i].balance-=wd;
printf("출금완료\n");
}
}
}
}
int show(){
for (int i = 0; i < accNum; i++)
{
printf("-----------------------------------\n");
printf("계좌번호 : %d\n",accArr[i].id);
printf("이름 : %s\n",accArr[i].name);
printf("잔액 : %d\n",accArr[i].balance);
}
printf("총 %d개의 계좌가 있습니다.\n-----------------------------------",accNum);
printf("\n");
}
int main(){
int choice;
while(1){
showmenu();
printf("선택: ");
scanf("%d", &choice);
switch(choice){
case 1: make(); break;
case 2: deposit(); break;
case 3: withdraw(); break;
case 4: show(); break;
case 5: return 0;
default: printf("잘못된 입력\n");
}
}
}