Answer to Question #255234 in C# for Hars

Question #255234

Write a C# program that calculates the total sales amount of a company agent. In the main method, prompt the user to enter the agent’s name, the number of the units sold by the agent, the cost per unit and the discount percent offered (like 0.1 or 0.2).


A method CalculateSales takes the number of units and the unit cost. The method calculates the total amount of sales by multiplying the number of units times the cost.

Another method CalculateNetSales takes the total amount of sales (calculated in the CalculateSales ) and the discount percent, then it calculates the net sales amount by multiplying the total amount by discount percent then subtracting the total amount of sales from the result of the multiplication.


The main method prints out the agent’s name, the number of units sold and the net sales amount. (You must use placeholders and the currency code inside your print statement).


 



1
Expert's answer
2021-10-22T16:44:12-0400
using System;


namespace Questions
{
    class Program
    {
        static decimal CalculateSales(int units, decimal unitCost)
        {
            return units * unitCost;
        }
        static decimal CalculateNetSales(decimal totalAmountOfSales, decimal discount)
        {
            return totalAmountOfSales * (1 - discount);
        }
        static void Main()
        {
            Console.Write("Agent's name: ");
            string agentName = Console.ReadLine();


            Console.Write("\nUnits sold: ");
            int unitsSold = int.Parse(Console.ReadLine());


            Console.Write("\nUnit cost: ");
            decimal unitCost = decimal.Parse(Console.ReadLine());


            Console.Write("\nDiscount percent: ");
            decimal discountPercent = decimal.Parse(Console.ReadLine());


            decimal totalAmountOfSales = CalculateSales(unitsSold, unitCost);
            decimal netSales = CalculateNetSales(totalAmountOfSales, discountPercent);


            Console.WriteLine("\n\n");
            Console.WriteLine(string.Format("Agent's name: {0}", agentName));
            Console.WriteLine(string.Format("Total sales: ${0}", totalAmountOfSales.ToString("0.00")));
            Console.WriteLine(string.Format("Net sales: ${0}", netSales.ToString("0.00")));


            Console.WriteLine();
            Console.ReadKey();
        }
    }


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS