Supermarket Selfbuy machine

This program is supposed to enter the total, enter the amount the customer paid, calculate the change and tell how many dollars, quartes, nickels and pennies. The program has an error when I tried to calculate the total=5.67 and the amount paid=15.00 the change=9.39 Now Dollars=9, quarters=1,dimes=0, nickels=1,now her is the problem it gives me pennies=2 instead of pennies=3 This is what I Have and what do I have to change.

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
58
59
60
61
62
63
64
#include <iostream.h>
#include <stdlib.h>

using namespace std;

int main()
{
    float total, amount_paid, change;
    int dollar, quarters, dimes, nickels,pennies,choice;
    char ch;

do{
    cout<<endl;
    cout<<"\t Welcome to Qcc Cafeteria Program"<<endl;
    cout<<endl;
    cout<<"Please choose the following: \n";
    cout<<"\t1. Qcc Cafeteria Management. \n";
    cout<<endl;
    cout<<"Your choice: ";
    cin>>choice;

    cout<<"Enter the amount of the Check: $";  //Get the cost.
    cin>>total;

    cout<<"Enter the amount the customer paid: $"; //Get the amount to be paid.
    cin>>amount_paid;
    if(amount_paid<total){
       cout<<endl;
       cout<<"The customer owns more than that!"<<endl;
    }

    cout<<endl;
    change = amount_paid - total;
    cout<<"The change is: $"<<change<<endl;

    dollar = (int) change; //Determine dollar bills integer part of the change.
    cout<<"Number of Dollars Bills: "<<dollar<<endl;

    change = change - dollar; //Take off the dollars and determine the quarters.
    quarters = (int) (change*100)/25; //Multiply by 100 to convert cent's from dollars.
    cout<<"Number of Quarters: "<<quarters<<endl;

    change = change - quarters * (0.25); //Take off the quarters and determine the dimes.
    dimes = (int) (change*100)/10;
    cout<<"Number of Dimes: "<<dimes<<endl;

    change = change - dimes * (0.10);//Take off the dimes and determine the nickels.
    nickels = (int) (change*100)/5;
    cout<<"Number of Nickels: "<<nickels<<endl;

    change = change - nickels * (0.05); //Take off the nickels and determine the pennies.
    pennies = (int) (change*100)/1;
    cout<<"Number of Pennies: "<<pennies<<endl;

    cout<<"\nWould you like to try again (y/n): ";
    cin>>ch;

}while(ch == 'y' || ch == 'Y');

    system("PAUSE");
    return EXIT_SUCCESS;

}


floating point roundoff problem.

Topic archived. No new replies allowed.