In: Computer Science
using Visual Studio write a code containing a main() program that implements the coin change state machine in C++ according to the guidance given in Translating a state machine to C++ Test your code using prices 1 and 91 cents, and assume change is calculated from a dollar bill. Copy and paste your console output to a text editor and save the result in a single file named console.txt. Upload your exercise081.cpp and console.txt files to Canvas.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
#include<iostream>
using namespace std;
int main(){
int cents,copy;
int quarters,dimes,nickels,pennies;
cout<<"Enter cents [1-91]: ";
cin >> cents;
copy =cents;
quarters = cents/25; cents%=25;
dimes = cents/10; cents%=10;
nickels = cents/5; cents%=5;
pennies = cents;
cout<<"Here is the change for
"<<copy<<" cents:\n";
if(quarters!=0)
cout<<quarters<<" quarter
coin(s).\n";
if(dimes!=0)
cout<<dimes<<" dime coin(s).\n";
if(nickels!=0)
cout<<nickels<<" nickel coin(s).\n";
if(pennies!=0)
cout<<pennies<<" penny coin(s).\n";
return 0;
}
===================================================================
Enter cents [1-91]: 87
Here is the change for 87 cents:
3 quarter coin(s).
1 dime coin(s).
2 penny coin(s).
--------------------------------
Process exited after 3.856 seconds with return value 0
Press any key to continue . . .
Enter cents [1-91]: 91
Here is the change for 91 cents:
3 quarter coin(s).
1 dime coin(s).
1 nickel coin(s).
1 penny coin(s).
--------------------------------
Process exited after 0.963 seconds with return value 0
Press any key to continue . . .
Enter cents [1-91]: 75
Here is the change for 75 cents:
3 quarter coin(s).
--------------------------------
Process exited after 4.069 seconds with return value 0
Press any key to continue . . .