Change maker program remainder troubles.

This is a discussion on Change maker program remainder troubles. within the C++ Programming forums, part of the General Programming Boards category; I have to make a program into which the user enters their bill in a decimal number and the remainder ...

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

    Change maker program remainder troubles.

    I have to make a program into which the user enters their bill in a decimal number and the remainder is broken down into dollars, quarters, dimes, nickels and pennies. I learned how to use setprecision(x). Here's my code:
    Code:
    #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;
        getchar();
        
        restart:
        
        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.
    }
    
    getchar();
    return (0);
    }
    How do I use % to narrow it down? I'm stuck. :[

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,898
    The modulus operator (%) will not work with floating point numbers, so you will have to convert your floating point numbers to an int.


    Jim

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    I never put signature, but I decided to make an exception.

  4. #4
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    Sorry, I yet again double posted a new thread.
    A more detailed one is HERE, mods can close this one (thanks for the help btw).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with change program
    By f4ichick02 in forum C Programming
    Replies: 12
    Last Post: 10-21-2009, 03:49 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. More Program Troubles...
    By face_master in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 06:40 AM
  4. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 06:50 AM
  5. coin change program??
    By kelly in forum C++ Programming
    Replies: 3
    Last Post: 03-24-2002, 08:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21