Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions