Answer to Question #337821 in C# for SITHEMBELE

Question #337821

2. The Ion Realty 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.


1
Expert's answer
2022-05-06T18:34:46-0400
     internal class Program
    {
        class IonRealtySalesCorporation
        {
            public decimal[] MonthlySalesAmounts { get; set; }


            public IonRealtySalesCorporation(int NumberOfMonths)
            {
                MonthlySalesAmounts = new decimal[NumberOfMonths];
            }


            public override string ToString()
            {
                string report = "";
                for (int i = 0; i < MonthlySalesAmounts.Length; i++)
                {
                    report += $"Month number: {i + 1},sales this month: {MonthlySalesAmounts[i]}, " +
                        $"percentage of the total: {(int)(MonthlySalesAmounts[i]*100/ MonthlySalesAmounts.Sum())}%\n";
                }
                report += $"Total sales: {MonthlySalesAmounts.Sum()}";
                return report;
            }


        }
        static void Main(string[] args)
        {
            Console.Write("Enter the number of last months you want to receive a report for: ");
            IonRealtySalesCorporation ionRealtySalesCorporation = new IonRealtySalesCorporation(int.Parse(Console.ReadLine()));
            IncomeRecord(ionRealtySalesCorporation);
            Console.WriteLine(ionRealtySalesCorporation);
            Console.ReadKey();
        }


        static void IncomeRecord(IonRealtySalesCorporation ionRealtySalesCorporation)
        {
            for (int i = 0; i < ionRealtySalesCorporation.MonthlySalesAmounts.Length; i++)
            {
                Console.Write($"Enter the amount of income for {i + 1} month: ");
                ionRealtySalesCorporation.MonthlySalesAmounts[i] = decimal.Parse(Console.ReadLine());
            }
        }


    }

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
New on Blog
APPROVED BY CLIENTS