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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
#include <iostream>
using namespace std;
double dblPurchaseAmount, dblCashTendered, dblChangeDue, dblTotalChange;
void getInput();
void doTheMath(double, double);
void getOutput(double, double, double);
int main(int argc, char** argv)
{
getInput();
getOutput(dblPurchaseAmount, dblCashTendered, dblChangeDue);
doTheMath(dblPurchaseAmount, dblCashTendered);
return 0;
}
void getInput()
{
//Creating title
cout << "********The Change Machine********\n";
//Prompting user for input
cout << "Enter the amount of the purchase: ";
cin >> dblPurchaseAmount;
cout << "Enter cash tendered: ";
cin >> dblCashTendered;
cout << "\n";
}
void getOutput(double dblAmount, double dblCash, double dblChange)
{
//output section
//showing user results
cout << "Amount of purchase: ";
cout << dblPurchaseAmount;
cout << "\n";
cout << "Cash tendered: ";
cout << dblCashTendered;
cout << "\n";
cout << "Change owed: ";
cout << dblChangeDue;
cout << "\n";
}
void doTheMath(double dblAmount, double dblCash)
{
//Initiating variables
int intTwenty = 0, intTen = 0, intFive = 0, intOne = 0, intQuarters = 0, intDimes = 0, intNickels = 0, intPennies = 0;
dblTotalChange = dblCashTendered - dblPurchaseAmount;
dblChangeDue = dblTotalChange;
//Initating if statements
if (dblTotalChange >= 20)
{
do
{
dblTotalChange = dblTotalChange - 20;
intTwenty = intTwenty +1 ;
}
while (dblTotalChange > 20);
}
if (dblTotalChange >= 10)
{
do
{
dblTotalChange = dblTotalChange - 10;
intTen = intTen +1;
}
while (dblTotalChange > 10);
}
if (dblTotalChange >= 5)
{
do
{
dblTotalChange = dblTotalChange - 5;
intFive = intFive + 1;
}
while (dblTotalChange > 5);
}
if (dblTotalChange >= 1)
{
do
{
dblTotalChange = dblTotalChange - 1;
intOne = intOne + 1;
}
while (dblTotalChange > 1);
}
if (dblTotalChange >= 0.25)
{
do
{
dblTotalChange = dblTotalChange - 0.25;
intQuarters = intQuarters + 1;
}
while (dblTotalChange > 0.25);
}
if (dblTotalChange >= 0.10)
{
do
{
dblTotalChange = dblTotalChange - 0.10;
intDimes = intDimes + 1;
}
while (dblTotalChange > 0.10);
}
if (dblTotalChange >= 0.05)
{
do
{
dblTotalChange = dblTotalChange - 0.05;
intNickels = intNickels + 1;
}
while (dblTotalChange > 0.05);
}
if (dblTotalChange >= 0.01);
{
do
{
dblTotalChange = dblTotalChange - 0.01;
intPennies = intPennies + 1;
}
while (dblTotalChange >= 0.01);
}
//initating if statements
cout << "\n";
if (intTwenty > 0)
{
cout <<"The amount of twenties owed is: ";
cout << intTwenty;
cout <<"\n";
}
if (intTen > 0)
{
cout << "The amount of tens owed is: ";
cout << intTen;
cout << "\n";
}
if (intFive > 0)
{
cout << "The amount of fives owed is: ";
cout << intFive;
cout << "\n";
}
if (intOne > 0)
{
cout << "The amount of ones owed is: ";
cout << intOne;
cout << "\n";
}
if (intQuarters > 0)
{
cout << "The amount of quarters owed is: ";
cout << intQuarters;
cout << "\n";
}
if (intDimes > 0)
{
cout << "The amount of dimes owed is: ";
cout << intDimes;
cout << "\n";
}
if (intNickels > 0)
{
cout << "The amount of nickels owed is: ";
cout << intNickels;
cout << "\n";
}
if (intPennies > 0)
{
cout << "The amount of pennies owed is: ";
cout << intPennies;
cout << "\n";
}
}
|