Question

In: Computer Science

Write a program named MakeChange that calculates and displays the conversion of an entered number of...

Write a program named MakeChange that calculates and displays the conversion of an entered number of dollars into currency denominations—twenties, tens, fives, and ones.

For example, if 113 dollars is entered, the output would be twenties: 5 tens: 1 fives: 0 ones: 3.

Answer in C#

(P.S i'm posting the incomplete code that i have so far below.)

using System;
using static System.Console;
class MakeChange
{
static void Main()
{
int twenties, tens, fives, ones;
WriteLine("Enter the number of dollars:");
int dollars = Convert.ToInt32(ReadLine());
twenties = dollars / 20;
dollars = dollars % 20;
tens = dollars / 10;
dollars = dollars % 10;
fives = dollars / 5;
dollars = dollars % 5;
ones = dollars / 1;
WriteLine("twenties:"+ twenties);
WriteLine("tens:"+ tens);
WriteLine("fives:"+ fives);
WriteLine("ones:"+ ones);
}
}

Solutions

Expert Solution

CORRECTED C# CODE:

using System;

class MakeChange
{
   static void Main()
   {
       //variable to stores the denominations
       int twenties, tens, fives, ones;
      
       //getting the user input
       Console.WriteLine("Enter the number of dollars:");
       int dollars = Convert.ToInt32(Console.ReadLine());

       // calculating the number of twenties
       twenties = dollars / 20;
       dollars = dollars % 20;

       // calculating the number of tens
       tens = dollars / 10;
       dollars = dollars % 10;

       // calculating the number of fives
       fives = dollars / 5;
       dollars = dollars % 5;

       // calculating the number of ones
       ones = dollars / 1;

       //displaying the denominations
       Console.WriteLine("\ntwenties:"+ twenties);
       Console.WriteLine("tens:"+ tens);
       Console.WriteLine("fives:"+ fives);
       Console.WriteLine("ones:"+ ones);
   }
}

SCREENSHOT FOR OUTPUT:


Related Solutions

Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the internet. Python 3
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels,...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels, filled with a random color at a random location on the screen. When you click the circle, it disappears and a new random color circle is displayed at another random location (see display below). After twenty circles are clicked, display the time spent in the pane. To detect whether a point is inside the circle, use the contains method defined in the Node class....
Your program should be in a new project named "Program 3: Number System Conversion" and should...
Your program should be in a new project named "Program 3: Number System Conversion" and should be in a package named "numberSystem". Your program must be in a file called "Program3NumberConversion.java". Your goal is to convert a number in some other number system (such as binary) to decimal. The base (also known as a radix) will have a maximum of 16. Before beginning your main method, write two other methods: public static int parseNumber (char letter) will basically be a...
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Write a Java program that calculates a random number 1 through 100. The program then asks...
Write a Java program that calculates a random number 1 through 100. The program then asks the user to guess the number.If the user guesses too high or too low then the program should output "too high" or "too low" accordingly.The program must let the user continue to guess until the user correctly guesses the number. ★Modify the program to output how many guesses it took the user to correctly guess the right number
Write a program that calculates the floor of a decimal number as defined here. Basically the...
Write a program that calculates the floor of a decimal number as defined here. Basically the Floor of any decimal number x, is the nearest whole number less than or equal to x. ( Code Should Be In C++) Requirements 1) You must implement a function to calculate the floor (you cannot use C++'s floor function). Name it floorAndError). It will have a return value and a single parameter 2) The program will ask the user to input a number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT