Change Calculator using loops

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;
}
Hello tundabolt,

One reason you have not received any replies yet is because your post makes it look like you are asking for someone else to do your work.

As keskiverto once said:

Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

Or say that you do not understand the instructions or how to figure them out.

Make some attempt and post what you have done.

A basic header file and ".cpp" is easy to start with. At least to get the program to compile.

Not sure exactly what to search for, but there are many examples of what you need to do here.

Andy
Topic archived. No new replies allowed.