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!
#include <iostream>
usingnamespace 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;
}