No matter what I put in for cost of item change comes back as zero?
Is there a way to see what value is being passed from first set of code to the second? I have tried multiple things but none seem to work.
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double userNumber, cost, taxOwed,taxRate, totalOwed;
int roundedNumber;
taxRate = .075;
cout << "Please enter the cost of the item purchasing: ";
cin >> userNumber; // input the amount of cost
cost = userNumber / 100;
taxOwed = cost * taxRate;
cout << "The cost of the item you entered is: " << cost << endl;
cout << "The amount of taxed owed on item is: " << taxOwed << endl;
totalOwed = cost + taxOwed;
std::cout << setprecision(2);
roundedNumber = static_cast<int>(totalOwed + .5);
cout << "The total amount you owe is: " << totalOwed;
int change, quarters, dimes, nickels, pennies;
change = totalOwed;
quarters = change / 25;
change = change % 25;
dimes = change / 10;
change = change % 10;
nickels = change / 5;
pennies = change % 5;
cout << "\n\n Quarters: " << quarters << endl; // display # of quarters
cout << " Dimes: " << dimes << endl; // display # of dimes
cout << " Nickels: " << nickels << endl; // display # of nickels
cout << " Pennies: " << pennies << endl; // display # of pennies
return 0;
}
Please enter the cost of the item purchasing: 61
The cost of the item you entered is: 0.61
The amount of taxed owed on item is: 0.04575
The total amount you owe is: 0.66
Quarters: 0
Dimes: 0
Nickels: 0
Pennies: 0
With above cost should get back
Quarter 1
Dime 1
Nickel 0
Pennies 4
The +0.5 is ensuring rounding to the nearest integer once you assign a double to an int. A simple cast - or just a straight assignment - would truncate down. e.g. 33.999 would truncate to a not-very-close 33.
I'm guessing that your change is from 100. You never state it.
Oh, and I don't know much about American coinage - I'm from the other side of the pond.