Thread: Change Maker (problems with %)

  1. #1
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Eastern-Central PA

    Question Change Maker (problems with %)

    OK, so for school, I have to make a program that illustrates the change a person should get based on a few monetary inputs. I'm crafting one that does so in the following steps:

    1. User inputs monetary value (e.g. 17.34 for $17.34) describing the original bill.

    2. User inputs monetary value describing how much cash they paid.

    3a. If the amount paid is less than the bill, it tells you that you still owe the difference (which is produced).

    3b. If the amount paid is more than the bill, it illustrates the most efficient change you should get, in dollars, quarters, dimes, nickels, and pennies.

    3b is where I'm stuck. I know that inputting, for example, (25 % 3) would return the remainder of 25 / 3, which is 1. However, I want to divide, say, 25 by 3, return the 8, and keep the one to work with in the next step.

    This is confusing me. D:

    Oh yeah, here's my code so far (don't yell at me for the goto, I only used it once. Feel free to toss a way to not use it my way, though.)

    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main() {
        double bill, paid, dollars, quarters, dimes, nickels, pennies, remaindol = (paid - bill);
        cout << "Welcome to my change-maker program! " << endl;
        cout << "To begin, press ENTER. " << endl;
        cout << "\n\nEnter how much the bill is. " << endl;
        cout << "Do not use a $ sign. Just enter the decimal number. " << endl;
        cin >> bill;
        cout << "Now enter how much cash you paid. " << endl;
        cin >> paid;
        if (paid < bill) {
                 cout << "Uh-oh! You need to pay more cash. You " << endl;
                 cout << "haven't paid the whole bill yet. " << endl;
                 cout << "You still owe " << setprecision(2) << fixed << (bill - paid) << ". " << endl;
                 goto restart;
        if (bill <= paid) {
                 cout << "You should get " << (paid - bill) << " in change. " << endl;
                 cout << "The most efficient way to get your " << (paid - bill) << " would " << endl;
                 cout << "be to get: " << endl;
                 //need to fit in change. narrow down.
    return (0);

  2. #2
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Eastern-Central PA
    OK I have it figured out except one thing: how do you make some variables in and some double? CAN you do that?

  3. #3
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Middle of NoWhere
    What do you really mean by to make some variables int and some double???
    int x,y;
    double a,b;
    Ain't this???

    .......So simple ...

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change Maker (problems with %)
    By muffinman8641 in forum C++ Programming
    Replies: 37
    Last Post: 03-11-2011, 07:04 AM
  2. Change maker program remainder troubles.
    By muffinman8641 in forum C++ Programming
    Replies: 3
    Last Post: 03-07-2011, 01:41 PM
  3. Making a change counting program
    By Scrogdor in forum C Programming
    Replies: 15
    Last Post: 02-23-2011, 12:00 PM
  4. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM