In: Computer Science
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);
}
}
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: