-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2.cpp
More file actions
131 lines (129 loc) · 3.53 KB
/
Assignment2.cpp
File metadata and controls
131 lines (129 loc) · 3.53 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
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
#include <iostream>
using namespace std;
//Delcaring all my functions
int getAmount();
int getFifty(int val);
int getTwenty(int val);
int getTen(int val);
int getFive(int val);
int getOne(int val);
int main() {
//Assinging variables for the programs
int bills, moneyLeft, withdrawal, fifty, twenty, ten, five, one;
int value = 0;
char choice = 'Y';
//While loop for when the user enters Y to continue with other withdrawals
while (choice == 'y' || choice == 'Y') {
//Function call to get amount
withdrawal = getAmount();
//Used an if statement to break the while loop if user enters '0' per functional requirements
if (withdrawal == 0)
break;
moneyLeft = withdrawal;
//Function call to get amount of $50 bills and adjustment of what is left from withdrawal
fifty = getFifty(moneyLeft);
withdrawal = withdrawal - (fifty * 50);
moneyLeft = withdrawal;
//Function call to get amount of $20 bills and adjustment of what is left from withdrawal
twenty = getTwenty(moneyLeft);
withdrawal = withdrawal - (twenty * 20);
moneyLeft = withdrawal;
//Function call to get amount of $10 bills and adjustment of what is left from withdrawal
ten = getTen(moneyLeft);
withdrawal = withdrawal - (ten * 10);
moneyLeft = withdrawal;
//Function call to get amount of $5 bills and adjustment of what is left from withdrawal
five = getFive(moneyLeft);
withdrawal = withdrawal - (five * 5);
moneyLeft = withdrawal;
//Function call to get amount of $1 bills and adjustment of what is left from withdrawal
one = getOne(moneyLeft);
withdrawal = withdrawal - (one * 1);
//I used if functions to ensure that each function is called and checked to make sure that if any bill was 0, then it won't be displayed.
if (fifty > 0) {
cout << "You have " << fifty << " $50.00 bills" << endl;
}
if (twenty > 0) {
cout << "You have " << twenty << " $20.00 bills" << endl;
}
if (ten > 0) {
cout << "You have " << ten << " $10.00 bills" << endl;
}
if (five > 0) {
cout << "You have " << five << " $5.00 bills" << endl;
}
if (one > 0) {
cout << "You have " << one << " $1.00 bills" << endl;
}
//Output to user for another withdrawal
cout << "Another withdrawal?" << endl;
cin >> choice;
}
system("pause");
return 0;
}
//function to get amount of withdrawal, while checking if amount if indeed between 1 and 300
int getAmount() {
int value;
do {
cout << "Please enter withdrawal amount ---> " << endl;
cin >> value;
if (value == 0)
break;
else if (value >= 300)
cout << "Max amount to withdraw is 300..." << endl;
else if (value <= 1)
cout << "Minimum amount to withdraw is 1..." << endl;
} while (value >= 300 || value <=1 || value==0);
return value;
}
//function to get amount of $50 bills
int getFifty(int val) {
int bills = val;
int fiftyCount=0;
while (bills >= 50) {
bills -= 50;
++fiftyCount;
}
return fiftyCount;
}
//function to get amount of $20 bills
int getTwenty(int val) {
int bills = val;
int twentyCount = 0;
while (bills >= 20) {
bills -= 20;
++twentyCount;
}
return twentyCount;
}
//function to get amount of $10 bills
int getTen(int val) {
int bills = val;
int tenCount = 0;
while (bills >= 10) {
bills -= 10;
++tenCount;
}
return tenCount;
}
//function to get amount of $5 bills
int getFive(int val) {
int bills = val;
int fiveCount = 0;
while (bills >= 5) {
bills -= 5;
++fiveCount;
}
return fiveCount;
}
//function to get amount of $1 bills
int getOne(int val) {
int bills = val;
int oneCount = 0;
while (bills >= 1) {
bills -= 1;
++oneCount;
}
return oneCount;
}