-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankomat.c
164 lines (148 loc) · 3.13 KB
/
bankomat.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
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
#include <stdio.h>
#include <stdbool.h>
//zapros na terminal ili bankomat
//bankomat
//zapros nomera scheta
//proverka scheta
//balans
//sniatie
//terminal
//zapros nomera scheta
//proverka scheta
//balans
//popolnenie
char Bankomat_or_terminal()
{
char vibor = '0';
printf("\nchem hotite vjspolzovatsa?\n\nBANKOMAT 1.\nTERMINAL 2.\nEXIT 3.\n\nVvedite vash vibor: ");
while (vibor<'1' || vibor>'3')
{
scanf(" %c", &vibor);
if (vibor <'1' || vibor > '3')
printf("\nNepravlnij vvod, vvedite 1, 2 ili 3: ");
}
return vibor;
}
void Balance(int schet, int* scheta)
{
printf("Vash balance %i$\n", scheta[schet]);
}
void Popolnenie(int schet, int* scheta)
{
int cashin;
printf("\nNa skol'ko jelaete popolllnit'? ");
scanf(" %i", &cashin);
if (cashin<1)
{
printf("Nevozmojno\n");
}
else
{
scheta[schet]+=cashin;
printf("\nVash schet popolnen na %i$\n", cashin);
}
}
void Vidacha(int schet, int* scheta)
{
int vidacha;
printf("\nSkol'ko jelaete snat'? ");
scanf(" %i", &vidacha);
if (vidacha > scheta[schet])
{
printf("nedostatochno sredstv, popolnite schet v terminale\n");
}
else if(vidacha <1)
{
printf("Nevozmojno\n");
}
else
{
printf("s vashego scheta spisano %i$,zaberite vashi den'gi\n %i$", vidacha, vidacha);
scheta[schet]-=vidacha;
}
}
bool Proverka_scheta(int size, int schet)
{
if (schet > 0 && schet < size)
{
return true;
}
printf("\nnepravil'nij nomer scheta, pjprobyjte esche");
return false;
}
void Terminal ( int size, int* scheta)
{
int schet = 0;
printf("\nVvedite nomer scheta: ");
scanf(" %i", &schet);
if (Proverka_scheta ( size, schet ))
{
char vibor = '0';
printf("\nPosmotret balans 1\nPopolnit' schet 2\n");
while (vibor<'1' || vibor>'2')
{
scanf(" %c", &vibor);
if (vibor !='1' && vibor != '2')
{
printf("\nNepravlnij vvod, vvedite 1 ili 2: ");
}
}
if (vibor == '1')
{
Balance (schet, scheta);
}
else
{
Popolnenie (schet, scheta);
}
}
}
void Bankomat ( int size, int* scheta)
{
int schet = 0;
printf("\nVvedite nomer scheta: ");
scanf(" %i", &schet);
if (Proverka_scheta ( size, schet ))
{
char vibor = '0';
printf("\nPosmotret balance 1\nVidacha nalichnih 2\n");
while (vibor<'1' || vibor>'2')
{
scanf(" %c", &vibor);
if (vibor !='1' && vibor != '2')
printf("\nNepravlnij vvod, vvedite 1 ili 2: ");
}
if (vibor == '1')
{
Balance (schet, scheta);
}
else
{
Vidacha (schet, scheta);
}
}
}
int main()
{
const int size = 100;
int scheta[size];
for (int i=0; i<size; i++)
scheta[i] = 0;
char b_or_t = '1';
while (b_or_t == '1' || b_or_t == '2')
{
char b_or_t = Bankomat_or_terminal();
if( b_or_t == '1')
{
Bankomat (size, scheta);
}
else if(b_or_t == '2')
{
Terminal (size, scheta);
}
else
{
break;
}
}
}