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...
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...
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 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...
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
1.Write a Java program that inputs a binary number and displays the same number in decimal....
1.Write a Java program that inputs a binary number and displays the same number in decimal. 2.Write Java program that inputs a decimal number and displays the same number in binary.
write a program that computes and displays the number of days that have elapsed between January...
write a program that computes and displays the number of days that have elapsed between January 1, 1900 and today (the day the program is run). The program must be designed as follows: Within a class named Elapsed_Days, provide the following functions: • bool is_year_valid(long year) returns true if year is >= 1900; otherwise false • bool is_month_valid(long month) returns true if month is between 1 and 12 (inclusive); otherwise false • bool is_leap_year(long year) returns true if year is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT