-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanking.cpp
More file actions
61 lines (54 loc) · 1.75 KB
/
Copy pathbanking.cpp
File metadata and controls
61 lines (54 loc) · 1.75 KB
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
#include<iostream>
#include<iomanip>
#include<limits>
using namespace std;
double deposit(double current_balance, double deposit);
double withdraw(double current_balance, double withdraw);
int main() {
double current_balance, deposit1, withdraw1;
int choice;
string option;
current_balance= 10000;
do {
cout<< "1. Show balance\n2. Menu\n3. EXIT!\n";
cin>> choice;
if(cin.fail()){
cin.clear();
cin.ignore(numeric_limits<streamsize> ::max(), '\n');
cout<< "Invalid Input!\n";
continue;
}
switch(choice) {
case 1:cout<<"Your current balance is: $" << setprecision(2) << fixed << current_balance <<endl;
break;
case 2: cout<<"You want to deposit or withdraw?"<<endl;
cin>> option;
if (option == "deposit") {
cout<<"Amount: "<<endl;
cin>> deposit1;
current_balance = deposit(current_balance, deposit1);
} else if ( option == "withdraw") {
do {
cout<<"Amount? (Must be less than current balance): "<<endl;
cin>> withdraw1;
}while(withdraw1 > current_balance);
current_balance = withdraw(current_balance, withdraw1);
} else {
cout<< "Please enter the valid option.\n";
}
break;
case 3: cout<<"Thank you for using this system!\n";
break;
default: cout<< "Invalid Input!\n";
break;
}
} while (choice != 3);
cout<<"Your current balance is: $" << current_balance<<endl;
return 0;
}
double deposit(double current_balance, double deposit) {
return current_balance + deposit;
}
double withdraw(double current_balance, double withdraw) {
return current_balance - withdraw;
}