Answer to Question #204461 in C# for Bhavesh Pillay

Question #204461

The ADSM Sales Corporation would like to have a listing of their sales over the past few months. Write a program that accepts any number of monthly sales amounts. Display the total of the values. Display a report showing each original value entered and the percentage that value contributes to the total. You may prompt the user for the number of values to be inputted. Use array to complete the task.


1
Expert's answer
2021-06-08T02:13:23-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q204461
{
    class Program
    {

        static void Main(string[] args){

            int numberSales = 0;
            double[] sales;
            Console.Write("Enter number of sales: ");
            int.TryParse(Console.ReadLine(),out numberSales);
            sales = new double[numberSales];
            for (int sale = 0; sale < numberSales; sale++){
                Console.Write("Enter sale #{0}: ", (sale + 1));
                double.TryParse(Console.ReadLine(), out sales[sale]);
            }

            double totalSales = sales.Sum();
            for (int sale = 0; sale < numberSales; sale++)
            {
                double contribution = sales[sale] / totalSales;
                Console.WriteLine("Sale # {0} was {1:C2} and contributed {2:P2}", (sale + 1), sales[sale], contribution);
            }
            Console.WriteLine("Total sum of sales is: {0:C2}", totalSales);


            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