Write program to compute the coins necessary to return change made up of quarters, dimes, nickels, and pennies.
We are not allowed to use if/else or loops in this program.
I am a beginner who knows very little about C++. We are working from Deitel's fourth edition and using the Visual C++ 6.0 compiler. I have worked for days on this problem and cannot figure out the logic part of it.
I am using Windows 95 right now and don't have a compiler but have access to one later.
This is what I have so far:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- void main ()
- {
- float Qvalue=.25;//The value of a quarter
- float Dvalue=.10;//The value of a dime
- float Nvalue=.05;//The value of a nickel
- float Pvalue=.01;//The value of a penny
- float change_amt;//Memory for user input
- int Qcount=0;//Initialize quarter count to 0
- int Dcount=0;//Initialize dime count to 0
- int Ncount=0;//Initialize nickel count to 0
- int Pcount=0;//Initialize penny count to 0
- Qcount+=1;//Increment Qcount by 1
- Dcount+=1;//Increment Dcount by 1
- Ncount+=1;//Increment Ncount by 1
- Pcount+=1;//Increment Pcount by 1
- cout<<"Enter change amount in 2 digit decimal format" <<"\n";
- cin>>change_amt;//2 digit decimal format only
- (change_amt !<=.00) || (change_amt !>.99);
- cout<<"Change is comprised of:"
- <<Qcount "Quarter(s)" "\n"
- <<Dcount "Dime(s)" "\n"
- <<Ncount "Nickel(s)" "\n"
- <<Pcount "Penny/Pennies" "\n";
- return 0;
- }
Divide change by Qvalue and somehow using % to go from quarters to dimes, nickels and pennies using the leftovers?
The maximum count for Quarters is 3
The maximum count for Dimes is 2
The maximum count for Nickels is 1
The maximum count for Pennies is 4
The Coin counters have to be reset somehow for each input amount.
The assignment is due on February 20th.
Thanks for your help.