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
|
#include <iostream>
#include <cmath>
using namespace std;
int inputAmountGiven(int& amountGiven);
int coinsUsed(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed);
void output(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed, char input);
int main()
{
char input = 'y';
while (input == 'y')
{
int inputAmountGiven(int& amountGiven);
cout << "Enter y to repeat, any other key to quit " << endl;
cin >> input;
}
}
int inputAmountGiven(int& amountGiven)
{
cout << "Enter amount of cents from 1 to 99: " << endl;
cin >> amountGiven;
return 0;
}
int quartersUsed = 0, dimesUsed = 0, penniesUsed = 0;
int coinsUsed(int amountGiven, int quartersUsed, int dimesUsed, int penniesUsed)
{
if (amountGiven >= 25)
{
quartersUsed = amountGiven / 25;
}
else quartersUsed = 0;
if (amountGiven - quartersUsed >= 10)
{
dimesUsed = (amountGiven % 25) / 10;
}
else dimesUsed = 0;
if (amountGiven - quartersUsed - dimesUsed > 0)
{
penniesUsed = amountGiven - (quartersUsed * 25) - (dimesUsed * 10);
}
return quartersUsed, dimesUsed, penniesUsed;
}
void output(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed, char input)
{
cout << amountGiven << " is equal to " << quartersUsed << " quarters, " << dimesUsed << " dimes, and " << penniesUsed << " pennies. \nEnter y to go again or any other key to end. " << endl;
cin >> input;
}
|