-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpiggy_bank.c
86 lines (55 loc) · 1.15 KB
/
piggy_bank.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
/*
Mini piggy bank
@author - bhansa
@createdon - 09/072017
*/
//Let's declare our global variable which will be alive all the way
// Let's have initial balance 100$
int total_balance;
#include<stdio.h>
void menu(){
//printing menu
printf("\n************ WELCOME to Piggy Bank ************\n");
printf("\t1. Deposit Money\n");
printf("\t2. Withdraw Money\n");
printf("\t3. Show Balance\n");
printf("\t4. Exit\n");
}
void deposit(int balance){
total_balance += balance;
}
void withdraw(int balance){
total_balance -= balance;
}
int showBalance(){
return total_balance;
}
int main(){
int choice, balance;
do{
menu();
printf("\tEnter your choice: ");
scanf("%d", &choice);
//using switch case
switch(choice){
case 1:
printf("\tEnter Amount: ");
scanf("%d", &balance);
deposit(balance);
break;
case 2:
printf("\tEnter Amount: ");
scanf("%d", &balance);
withdraw(balance);
break;
case 3:
printf("\tCurrent Balance: %d\n",showBalance());
break;
case 4:
break;
default:
printf("\tWrong Choice\n");
}
}while(choice != 4);
printf("\tThank you for visiting.\n");
}