-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeManager.cpp
executable file
·102 lines (90 loc) · 2.73 KB
/
ChangeManager.cpp
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
#include "ChangeManager.h"
ChangeManager::ChangeManager()
{
quartersLeft = 0;
dimesLeft = 0;
nickelsLeft = 0;
}
ChangeManager::ChangeManager(int quarterLeft, int dimeLeft, int nickelLeft)
{
quartersLeft = quarterLeft;
dimesLeft = dimeLeft;
nickelsLeft = nickelLeft;
}
int ChangeManager::QuartersLeft()
{
return quartersLeft;
}
int ChangeManager::DimesLeft()
{
return dimesLeft;
}
int ChangeManager::NickelsLeft()
{
return nickelsLeft;
}
void ChangeManager::addCoin(int coinValue)
{
if (coinValue == QUARTERS)
{
quartersLeft++;
}
if (coinValue == DIMES)
{
dimesLeft++;
}
if (coinValue == NICKELS)
{
nickelsLeft++;
}
}
void ChangeManager::customerChange(int customerPaid, int drinkPrice)
{
if(customerPaid > drinkPrice)
{
int returned = 0;
do
{
if(returned+QUARTERS <= customerPaid-drinkPrice && QuartersLeft() > 0)
{
returned += QUARTERS;
// std::cout << customerPaid-drinkPrice << " cents Returned." << std::endl;
quartersLeft--;
}
else if(QuartersLeft() <= 0)
{
std::cout << "Out of Quarters! Sorry!" << std::endl;
break;
}
if(returned+DIMES <= customerPaid-drinkPrice && DimesLeft() > 0)
{
returned += DIMES;
// std::cout << customerPaid-drinkPrice << " cents Returned." << std::endl;
dimesLeft--;
}
else if(DimesLeft() <= 0)
{
std::cout << "Out of Dimes! Sorry!" << std::endl;
break;
}
if(returned+NICKELS <= customerPaid-drinkPrice && NickelsLeft() > 0)
{
returned += NICKELS;
// std::cout << customerPaid-drinkPrice << " cents Returned." << std::endl;
nickelsLeft--;
}
else if(NickelsLeft() <= 0)
{
std::cout << "Out of Nickels! Sorry!" << std::endl;
break;
}
} while(returned < customerPaid-drinkPrice);
if(returned != customerPaid-drinkPrice)
std::cout << "Only " << returned << " cents returned out of " << customerPaid-drinkPrice << " . Sorry!" << std::endl;
else
std::cout << returned << " cents returned" << std::endl;
}
else
std::cout << "No change returned, Thank you!" << std::endl;
std::cout << "I currently have " << quartersLeft << " Quarters, " << dimesLeft << " Dimes, and " << nickelsLeft << " Nickels left." << std::endl;
}