In: Computer Science
Take the pseudocode that you developed in your previous
assignment - and convert it into a working program. Or if you think
of a better way of creating a working program – such as what we
discuss in class.
The task was: Write the pseudocode for helping a cashier give you
the correct change. Assume that a person brings hundreds to pennies
to you and wishes to the receive quarters, dimes, and nickels back.
There is a single input of the number of pennies given to the
cashier. There will be several outputs: the number of five dollar
bills, one dollar bills, quarters, dimes, nickels, and remaining
pennies to be returned.
For the input, you will ask the user to enter the number of pennies
(as an integer value) that he/she has. The output will be the
Number of Five Dollar Bills, Number of One Dollar Bills, Quarters,
Number of Dimes, Number of Nickels, and Number of Pennies. Each of
the outputs should be integer values as well.
Provide me with just the source code for this task.
Sample Input:
Enter the number of pennies:
136
Sample Output:
Your change is:
Five Dollar Bills: 0
One Dollar Bills: 1
Quarters: 1
Dimes: 1
Nickels: 0
Pennies: 1
pseudocode :
Function main
PRINT "Enter the number of pennies: "
READ(pennies)
Number_of_Five_Dollar_Bills = pennies/500
remaining_pennies = pennies%500
Number_of_One_Dollar_Bills =
remaining_pennies/100
remaining_pennies = remaining_pennies%100
Number_of_Quarters = remaining_pennies/25
remaining_pennies = remaining_pennies%25
Number_of_Dimes = remaining_pennies/10
remaining_pennies = remaining_pennies%10
Number_of_Nickels = remaining_pennies/5
remaining_pennies = remaining_pennies%5
pennies = remaining_pennies
PRINT "Your change is:"
PRINT("Five Dollar Bills:",
Number_of_Five_Dollar_Bills)
PRINT("One Dollar Bills:",
Number_of_One_Dollar_Bills)
PRINT("Quarters:", Number_of_Quarters)
PRINT("Dimes:", Number_of_Dimes)
PRINT("Nickels:", Number_of_Nickels)
PRINT("pennies:", Number_of_pennies)
End Function
C++ Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int pennies;
cout<<"Enter the number of pennies: ";
cin>>pennies;
int Number_of_Five_Dollar_Bills = pennies/500;
int remaining_pennies = pennies%500;
int Number_of_One_Dollar_Bills =
remaining_pennies/100;
remaining_pennies = remaining_pennies%100;
int Number_of_Quarters = remaining_pennies/25;
remaining_pennies = remaining_pennies%25;
int Number_of_Dimes = remaining_pennies/10;
remaining_pennies = remaining_pennies%10;
int Number_of_Nickels = remaining_pennies/5;
remaining_pennies = remaining_pennies%5;
pennies = remaining_pennies;
cout<<"Your change is:"<<'\n';
cout<<"Five Dollar
Bills:"<<Number_of_Five_Dollar_Bills<<'\n';
cout<<"One Dollar
Bills:"<<Number_of_One_Dollar_Bills<<'\n';
cout<<"Quarters:"<<Number_of_Quarters<<'\n';
cout<<"Dimes:"<<Number_of_Dimes<<'\n';
cout<<"Nickels:"<<Number_of_Nickels<<'\n';
cout<<"pennies:"<<pennies<<'\n';
return 0;
}