Question: In c# R ewrite problem 2(copy your solution from problem 2 and paste it into a separate file) and create a function called CalcAmount. This

In c#

Rewrite problem 2(copy your solution from problem 2 and paste it into a separate file) and create a function called CalcAmount. This function will take 4 integers for the change amount and convert that change into dollars. The dollar amount calculated will be passed back through the return statement, where the amount should be outputted in main. Note that to receive credit for this problem, you may ONLY have Console.Write and Console.Read statements in the main function. Refer to the output of Problem 1 for this problems output.

Source Code

using System; // import System namespace

class CoinCalculator //coinCalculator class

{

static void Main(string[] args) // main function

{

Console.Write("How many quarters: "); // print message

int quarters = int.Parse(Console.ReadLine()); // read input as quarters

Console.Write("How many dimes: "); // print message

int dimes = int.Parse(Console.ReadLine()); // read input as dimes

Console.Write("How many nickels: "); // print message

int nickels = int.Parse(Console.ReadLine()); // read input as nickels

Console.Write("How many pennies: "); // print message

int pennies = int.Parse(Console.ReadLine()); // read input as pennies

decimal total = (decimal)(quarters * 0.25) + (decimal)(dimes * 0.1) + (decimal)(nickels * 0.05) + (decimal)(pennies * 0.01); // calculate total

Console.WriteLine("Total amount: $" + total.ToString("0.00")); // print total amount with 2 decimal places

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!