Using Int in change calculator

I am trying to make a program in which you enter a dollar amount and it gives you the smallest coin denomination possible. This is what I have so far, but it has some rounding errors. I believe I have to use "int" but I don't really know how. Thank you in advance! Any hints are greatly appreciated!

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
  #include <iostream>
using namespace std;
int main ()
{
double input (0), quarters (0), dimes (0), nickels (0), pennies (0); //Define variables used in program
cout << "Change Calculator" << endl;// Title
{
cout << "Enter amount in US Dollars (DDDD.CC)  $ ";  // Ask user to Enter value
cin >> input;
}
cout << "$ " << input<< " in coin denomination is : " << endl;  // Tell user coin denomination

input= (int)(input *100); // Convert amount into pennies
//Calculate coins
while (input >= 25) //Loop for quarters, repeat until value is less than 25
{
input -= 25;
quarters++;
}
while (input >= 10)//Loop for dimes, repeat until value is less than 10
{
input -= 10;
dimes++;
} //Do dimes
while (input >= 5)//Loop for nickels, repeat until value is less than 5
{
input -= 5;
nickels++;
}
while (input >= 1)//Loop for pennies, repeat until no more coins left
{
input -= 1;
pennies++;
}
//Display on screen
cout << quarters << " quarter(s)" << endl;
cout << dimes << " dime(s)" << endl;
cout << nickels << " nickel(s)" << endl;
cout << pennies << " pennies" << endl;


}
Topic archived. No new replies allowed.