Answer to Question #132448 in C# for Dennis

Question #132448
A company distributes 5 different items around Nairobi through its 10 salesmen. Using arrays write a C# application program to input a salesman name and the corresponding sales made by each of the salesman for each of the item. The program should then output each of the salesman’s name, sales, total sales as well as grand total using the format shown below.
Name Item1 Item2 Item3 Item3 Item4 Item5 TotalSales
___________________________________________________
Brian 20 50 25 10 0 15 120
Joan 45 55 10 25 5 30 170
….
….
GrandTotal xx
1
Expert's answer
2020-09-11T18:03:57-0400
using System;

namespace СompanyNairobi
{
    class Program
    {
        static void Main(string[] args)
        {
            const short countSalesMen = 10;
            string[] salesmen = new string[countSalesMen];
            int[] items1 = new int[countSalesMen];
            int[] items2 = new int[countSalesMen];
            int[] items3 = new int[countSalesMen];
            int[] items4 = new int[countSalesMen];
            int[] items5 = new int[countSalesMen];

            for (int i = 0; i < countSalesMen; i++)
            {
                salesmen[i] = SetName();
                items1[i] = SetSales(1);
                items2[i] = SetSales(2);
                items3[i] = SetSales(3);
                items4[i] = SetSales(4);
                items5[i] = SetSales(5);
                Console.WriteLine();
            }

            long grandTotal = 0;
            Console.WriteLine("Name Item1 Item2 Item3 Item3 Item4 Item5 TotalSales");
            Console.WriteLine("---------------------------------------------------");
            for (int i = 0; i < countSalesMen; i++)
            {
                long totalSales = items1[i] + items2[i] + items3[i] + items4[i] + items5[i];
                grandTotal += totalSales;
                Console.WriteLine($"{salesmen[i]} {items1[i]} {items2[i]} {items3[i]} {items4[i]} {items5[i]} {totalSales}");
            }
            Console.WriteLine("---------------------------------------------------");
            Console.WriteLine($"GrandTotal {grandTotal}");
        }

        static string SetName()
        {
            Console.Write("Enter the salesmen name: ");
            return Console.ReadLine();
        }

        static int SetSales(short itemNumber)
        {
            int sales = 0;
            bool error = true;
            do
            {
                Console.Write($"Enter the sales made of the item{itemNumber}: ");
                try
                {
                    sales = Convert.ToInt32(Console.ReadLine());
                    error = false;
                }
                catch (Exception)
                {
                    Console.WriteLine("Input error. Please enter an integer.");
                }
            } while (error);

            return sales;
        }
    }
}

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