Hey all,
I'm really new to C++ and REALLY struggling with my online class. I'm stuck on a homework assignment where we have to create a program using a provided main.cpp file that we aren't allowed to edit (minus a mess up in the loop that was overlooked), and must create my_change_calculator.cpp and my_change_calculator.h files to run the formula. I'm mostly stuck on how to properly phrase the formula, I guess. Anyways, here's the code inside the main.cpp file and the assignment:
Write a C++ program that prompts for a cash value and an amount of purchases made against that amount. The program should then determine the change using US paper and coin currency. Working with the following bills and coins:
Fifty Cents, Twenty-Five Cents, Ten Cents, Five Cents, One Cent
One Dollar Bill, Five Dollar Bill, Ten Dollar Bill, Twenty Dollar Bill
display how many of each would be needed to make the change. In order to receive full credit, you must use a loop in the algorithm that performs the calculation. The program dialog would look like:
Enter a value: 32.00
Enter an amount of purchases made against this amount: 18.52
The remaining change is: 13.48
Twenty US Dollar Bills: 0
Ten US Dollar Bills: 1
Five US Dollar Bills: 0
One US Dollar Bills: 3
Fifty US Cents Coins: 0
Twenty-Five US Cents Coins: 1
Ten US Cents Coins: 2
Five US Cents Coins: 0
One US Cent Coins: 3
Continue(y/n)?n
HINT: You really should use integer arithmetic to ensure that your calculations, down to that very last penny, are exact and accurate.
HINT: The % (modulus operator) is very helpful in computing remainders but requires two int parameters.
Currency output must output to proper precision.
For example, 'The remaining change is: 1.200000' will result in deductions.
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
|
#include <iostream>
#include <string>
#include "my_change_calculator.h"
using namespace std;
int main() {
string cont = "y";
double cash = 0, purchase = 0;
while(cont != "n"){
//input
cout << "Enter total bill: ";
cin >> purchase;
cout << "Enter cash amount you provide: ";
cin >> cash;
//output
string output = calculateChange(purchase, cash);
cout << output;
//loop
cout << "Continue (y/n)? ";
cin >> cont;
}
return 0;
}
|