Problem is at
pennies = (int)(amount / 0.01);
if you want in INT you will always have answer in 0; so you cant calculate pennies.
so you have to change it to..
pennies = (amount / 0.01);
now another thing to do is.. make it round ....
int roundingp = pennies+0.5;
and then
pennies = roundingp;
if i paste your program after making some change here it will be !
Code:
# include <iostream.h>
#include<conio.h>
float amount;
float quarters;
float dimes;
float nickels;
float pennies;
int main()
{
cout << "Enter an amount less than $1.00: ";
cin >> amount;
//if (amount == 0)
quarters = (int)(amount / 0.25);
amount -= (quarters * 0.25);
dimes = (int)(amount / 0.10);
amount -= (dimes * 0.10);
nickels = (int)(amount / 0.05);
amount -= (nickels * 0.05);
pennies = (amount / 0.01);
//cout<< pennies;
cout << "You have " << quarters << " quarters" << ".\n";
cout << "You have " << dimes << " dimes" << ".\n";
cout << "You have " << nickels << " nickels" << ".\n";
int roundingp = pennies+0.5;
pennies = roundingp;
cout << "You have " << pennies << " pennies" << ".\n";
getch();
return 0;
}
Result Snapshopt
where input is 0.11
Enter an amount less then $1.00: 0.11
You have 0 quaters.
You have 1 dimes.
You have 0 quaters.
You have 1 pennies.
Reply if having any difficulty !
Bookmarks