-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch\case
47 lines (46 loc) · 1.36 KB
/
switch\case
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
#include <stdio.h>
int main(void) {
int balance = 2000 ;
int amount = 0, operation = 0, transfer = 0 ;
printf("Your balance is %d\n", balance) ;
printf("Choose your operations:\n") ;
printf("Choose '1' for withdraw:\n") ;
printf("Choose '2' for deposit:\n") ;
printf("Choose '3' for transfer:\n") ;
printf("Choose '4' for refund the card:\n") ;
scanf("%d", &operation) ;
switch(operation) {
case 1 :
printf("Enter your withdraw:\n") ;
scanf("%d", &amount);
if (balance >= amount) {
balance = balance - amount ;
printf("Your operation is succesfull:\n") ;
printf("Balance is %d\n", balance);
}else {if (balance < amount){
printf("You are poor.\n") ;
}} break ;
case 2 :
printf("Enter your deposit:") ;
scanf("%d", &amount) ;
balance = balance + amount ;
printf("Your balance is :%d", balance) ;
break ;
case 3 :
printf("Enter your transfer value:\n") ;
scanf("%d",&transfer) ;
if (balance >= transfer) {
balance = balance - transfer ;
printf("Your operation is succesfull:\n") ;
printf("Balance is :%d\n",balance) ;
}else {if (balance < transfer){
printf("Your money is not enough for this operation:\n");
}} break ;
case 4 :
printf("Your card is succesfully refund.\n") ;
break ;
default :
printf("Please enter a valid number.\n") ;
}
return 0 ;
}