In: Computer Science
USING C#
Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
Sample run 2:
Enter number of quarters: 3
Enter number of dimes: 0
Enter number of nickels: 0
Enter number of pennies: 3
You entered 3 quarters
You entered 0 dimes
You entered 0 nickels
You entered 3 pennies
Your total is 0 Dollars and 78 Cents.
using System;
class Program{
static void Main(string[] args){
int q,d,n,c;
int total=0;
int dollors=0,cents=0;
//reading coin details numbers from the console
Console.WriteLine("Enter number of quarters:");
q = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number of dimes:");
d = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number of nickles:");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number of cents:");
c = Convert.ToInt32(Console.ReadLine());
// displaing the entered details
Console.WriteLine("You enterd "+q+" quarters");
Console.WriteLine("You enterd "+d+" dimes");
Console.WriteLine("You enterd "+n+" nickles");
Console.WriteLine("You enterd "+c+" cents");
//converting into total cents
total=q*25+d*10+n*5+c;
//finding the dollors
dollors=total/100;
//finding the total cents
cents=total%100;
//displaying the details
Console.WriteLine("Your total "+dollors+" dollor and "+cents+" cents");
}
}