Question

In: Computer Science

Take the pseudocode that you developed in your previous assignment - and convert it into a...

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

Solutions

Expert Solution

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;
}


Related Solutions

I need this in pseudocode: Similar to the previous assignment, you’re going to read in the...
I need this in pseudocode: Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter the number...
pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read...
pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter...
(1)Using the Matlab code developed in Software Assignment #1: a. Convert the code that generates the...
(1)Using the Matlab code developed in Software Assignment #1: a. Convert the code that generates the random number (H,T) with equal probabilities into a function called myBernolli(p, S) that takes as an input the probability of success p and S is the outcome defined as success (either T or H) and returns the outcome of the trial (either T or H). b. Test that your function is actually producing the successful outcome with probability p by running the function in...
For this programming assignment, you will use your previous code that implemented a video game class...
For this programming assignment, you will use your previous code that implemented a video game class and objects with constructors. Add error checking to all your constructors, except the default constructor which does not require it. Make sure that the high score and number of times played is zero or greater (no negative values permitted). Also modify your set methods to do the same error checking. Finally add error checking to any input requested from the user. #include <iostream> #include...
Volunteers who had developed a cold within the previous 24 hours were randomly assigned to take...
Volunteers who had developed a cold within the previous 24 hours were randomly assigned to take either zinc or placebo lozenges every 2 to 3 hours until their cold symptoms were gone. Twenty-five participants took zinc lozenges and 23 participants took placebo lozenges. The mean overall duration of symptoms for the zinc lozenge group was 4.5 days with a standard deviation of 1.6 days. For the placebo group, the mean overall duration of symptoms was 8.1 days with a standard...
7.11 Volunteers who had developed a cold within the previous 24 hours were randomized to take...
7.11 Volunteers who had developed a cold within the previous 24 hours were randomized to take either zinc or placebo lozenges every 2 to 3 hours until their cold symptoms were gone. Twenty-five participants took zinc lozenges, and 23 participants took placebo lozenges. The mean overall duration (in days) of symptoms for the zinc lozenges group was 4.5 days, and the standard deviation of overall duration of symptoms was 1.6 days. For the placebo group, the mean overall duration of...
people who had developed a cold within the previous 24 hours were randomized to take either...
people who had developed a cold within the previous 24 hours were randomized to take either medicine A and medicine B every 5 to 6 hour until their cold were gone. 22 participants took medicine A and 25 participants took medicine B.The mean overall duration of symptoms was found for each group. We want test to see if the medicine A (a)What is the parameter of interest? Write it in words and use the correct symbol. (b)What are the Hn...
Volunteers who had developed a cold within the previous 24 hours were randomized to take either...
Volunteers who had developed a cold within the previous 24 hours were randomized to take either zinc or placebo lozenges every 2 to 3 hours until their cold symptoms were gone. Twenty-five participants took zinc lozenges, and 23 participants took placebo lozenges. The mean overall duration of symptoms for the zinc lozenge group was 4.5 days, and the standard deviation of overall duration of symptoms was 1.1 days. For the placebo group, the mean overall duration of symptoms was 8.6...
Locate your Student project from the previous in-class assignment. You will add a new class to...
Locate your Student project from the previous in-class assignment. You will add a new class to that project. 1. Create a class called Course. It should have a field to hold an ArrayList of Student objects. 2. Create a constructor for Course that accepts an ArrayList of Student objects, and set field to the parameter. 3. In the Course class, create a method called addStudent(Student s). This should add the parameter "s" to the ArrayList of Student objects. 4. In...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a month, then determine what season it is based on that input. Write a method that takes in a month and day and returns which season it is (“Spring”, “Summer”, “Fall”, “Winter”). Your main method should be the only one that includes a print statement. Note the first days of each season: • March 19th – Spring • June 20st – Summer • September 22nd...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT