Noob Question Here...c++

From: Eliot Bisky (afropuff_at_charter.net)
Date: 01/31/04


Date: Sat, 31 Jan 2004 11:19:39 -0600

Hello all,

           I have a real n00b question. I just started my c++ class about 2
weeks ago and we have an assignment. We have to make a program that makes
change, and then shows how many dollars/quarters/dimes/nickles/pennies in
change the customer gets back....

        I could swear my math is correct(I checked it on my calculator over
10 times), I just have no idea why it is not working correctly. It seems
the dollars/quarters/dimes seems to be working but the nickles and pennies
are kinda messed up...When I put an amount of $20.00 owed and $22.72 paid..I
of course get $2.72 in change...and then it displays 2 dollar 2 quarter 2
dime 0 nickle 1 penny.

Take a look at my code in C++:

//Program Purpose : To help students produce change from a sale

#include <iostream>
using namespace std;

int main()
{
 float owe = 0.0;
 float paid = 0.0;
 float change = 0.0;
 int dollar = 0 ;
 int quarter = 0 ;
 int dime = 0 ;
 int nickle = 0;
 int penny = 0;

 //enter input items
 cout << "Enter Amount Owed: " ;
 cin >> owe;
 cout << "Enter Amount Paid: " ;
 cin >> paid;

 //calculate total owed in change
 change = paid - owe;
 dollar = change / 1;
 quarter = (change - dollar) / .25;
 dime = (change - dollar - (quarter * .25)) / .1;
 nickle = (change - dollar - (quarter * .25) - (dime * .1)) / .05;
 penny = (change - dollar - (quarter * .25) - (dime * .1) - (nickle * .05))
/ .01;

 //display output items
 cout << "change: " << change << endl;
 cout << "dollar(s): " << dollar << endl;
 cout << "quarter(s): " << quarter << endl;
 cout << "dime(s): " << dime << endl;
 cout << "nickel(s): " << nickle << endl;
 cout << "penny(s): " << penny << endl;

 return 0;
}
//end main function

Thanks for the help!!

-EB