Hello! I am having issues with my code. My program is supposed to take a given amount of money (1.33) and tell how many quarters, dimes, nickels and pennies would make up this sum of money. Problem is when I multiply the input by 100, depending on the amount of money entered, I lose a penny. When I enter .34 it comes out correct, but when I enter .35, it gives me 34. Any and all help is greatly appreciated. Here is part of my code:
Code:
void ChangeMaker::Calc()
{
int q = 25;
int d = 10;
int n = 05;
int p = 01;
int remainderQ = 0;
int remainderD = 0;
int remainderN = 0;
int newAmount = static_cast<int>(amount * 100);
cout << newAmount << endl;
if(newAmount > .24)
{
quarters = (newAmount/q);
remainderQ = (newAmount % q);
}
if(remainderQ > .09)
{
dimes = (remainderQ/d);
remainderD = (remainderQ % d);
}
if(remainderD > .04)
{
nickels = (remainderD/n);
remainderN = (remainderD % n);
}
if(remainderN > .00)
{
pennies = remainderN;
}
}
Comment