#include <iostream>
using namespace std;
int main()
{
double purchase_amount;
double receive_amount;
double total_change;
double dollars;
double quarters;
double dimes;
double nickels;
double pennies;
cout << "Enter purchase amount: ";
cin >> purchase_amount;
cout << "Enter amount received: ";
cin >> receive_amount;
total_change = receive_amount - purchase_amount;
cout << "Total change: " << total_change;
dollars = total_change % 1;
cout << "Dollars: " << endl;
total_change = total_change - dollars * 1;
quarters = total_change % .25;
cout << "Quarters: " << endl;
total_change = total_change - quarters * .25;
dimes = total_change % .10;
cout << "Dimes: " << endl;
total_change = total_change - dimes * .10;
nickels = total_change % .05;
cout << "Nickels: " << endl;
total_change = total_change - nickels * .05;
pennies = total_change % .01;
cout << "Pennies: " << endl;
return 0;
}
Question about Cash Register change in change?
Page 1 of 15 Replies - 121 Views - Last Post: 28 January 2013 - 07:23 PM
#1
Question about Cash Register change in change?
Posted 28 January 2013 - 06:55 PM
So, the point of this assignment is to get the change for the customer in the exact quarters, dimes, nickels, and pennies. I have already calculated how to get the total change and everything. I feel like I have done how to get that exact change. I think think the only problem right now is changing the double to int for how many dollars, quarters, dimes, etc. that is needed (because you can't split coins, etc.) I know that static_cast<int> should be used, but I'm not quite sure how to use it. Here's what I have:
Replies To: Question about Cash Register change in change?
#2
Re: Question about Cash Register change in change?
Posted 28 January 2013 - 06:59 PM
Does this program even compile? You should be getting a few errors. The modulus operator% can't be used on floating point types, it only works with integer types.
Jim
Jim
#3
Re: Question about Cash Register change in change?
Posted 28 January 2013 - 07:06 PM
jimblumberg, on 28 January 2013 - 06:59 PM, said:
Does this program even compile? You should be getting a few errors. The modulus operator% can't be used on floating point types, it only works with integer types.
Jim
Jim
that's what the problem is. I know that using % only works with int. That's why I stated that I needed to use static_cast. and that's where the problem lies. I don't know how to implement it.
#4
Re: Question about Cash Register change in change?
Posted 28 January 2013 - 07:14 PM
Why aren't you using int for dollars, quarters, dimes, etc.? Can you have 1.1 quarters?
#5
Re: Question about Cash Register change in change?
Posted 28 January 2013 - 07:15 PM
If you consider that there are 100 pennies in a dollar, you can convert your floating point change amount to an integer value that represents the number of pennies.
#6
Re: Question about Cash Register change in change?
Posted 28 January 2013 - 07:23 PM
CTphpnwb, on 28 January 2013 - 07:14 PM, said:
Why aren't you using int for dollars, quarters, dimes, etc.? Can you have 1.1 quarters?
oh, thanks for that. I've changed it to int.
Skydiver, on 28 January 2013 - 07:15 PM, said:
If you consider that there are 100 pennies in a dollar, you can convert your floating point change amount to an integer value that represents the number of pennies.
our professor said we should be using static_cast to change the total change, or whatever into an int.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|