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...
I need to write this program in Python. Write a program that displays a temperature conversion...
I need to write this program in Python. Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The tabular format of the result should include rows for all temperatures between 70 and 270 degrees Celsius that are multiples of 10 degrees Celsius (check the sample below). Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit is as follow F=(9/5C) +32 Celsius Fahrenheit 70 158 80 176 90...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this course (CSC100 online) based on three user inputs. This program should begin by printing the title of the application (program) and a brief description of what it does. (Note: this is NOT the same as the program prolog: a prolog is much more detailed, has required elements, and is intended for other programmers reading the cpp file. The title and description displayed by the...
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
Write a java program called ImperialMetric that displays a conversion table for feet and inches to...
Write a java program called ImperialMetric that displays a conversion table for feet and inches to metres. The program should ask the user to enter the range of values that the table will hold. Here is an example of what should be output when the program runs: Enter the minimum number of feet (not less than 0): 5 Enter the maximum number of feet (not more than 30): 9 | | | | | | 0" 1.524 1.829 2.134 2.438...
Answer question in Python, show all code: Write a program that calculates and displays the end...
Answer question in Python, show all code: Write a program that calculates and displays the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years. For this problem, assume interest is calculated annually. (That is, if I put $1000 in a bank account at the beginning of the year, then the balance at the end of the year is $1,000 + $1,000*6%.) You may assume no money is removed...
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...
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....
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT