Mohammed Musekula

Mohammed Musekula

  • NA
  • 36
  • 10.5k

There are mistakes in my Arrays Spreedsheet application

Apr 12 2015 12:29 PM

I am a bit stuck with this script. I am unable to improve the script to work as intended. If you help me out I will be very grateful.

Here is the program below:

namespace SpreadsheetFunctionality

{

    class SpreedsheetFunctionality

    {

        static void Main(string[] args)

        {


            const int MAX_NUM_PRODUCTS = 100;

            double [ ] retailPrices = new double[MAX_NUM_PRODUCTS];

            string [ ] productNames = new string[MAX_NUM_PRODUCTS];

            int numberOfProducts = 0;

            int choice = 0;


            productNames[0] = "Golden Apple Watch";

            productNames[1] = "Swiss cuckoo clock";

            productNames[2] = "ACME watch";

 

            while (choice == 0)

            {

                Console.WriteLine("1. Add new product and price");

                Console.WriteLine("2. Update existing product price");

                Console.WriteLine("3. Calculate profits");

                Console.WriteLine("4. Calculate totals");

                Console.WriteLine("5. Exit");


 

                Console.WriteLine("Enter your option: ");

                int option = int.Parse(Console.ReadLine());

               

            

 

                switch (option)

                {

 

 

                    case 1:

 

 

                Console.WriteLine("Enter the name of a new product in your catalogue");

 

                        for (int i = 0; i <1; i++)

                        {

                            productNames[i] = Console.ReadLine();

                        }

 

                        Console.WriteLine("Enter the price for it");

                        for (int i = 0; i < 1; i++)

                        {

 

                            retailPrices[i] = int.Parse(Console.ReadLine());

                           

                        }

                       

                        

                     break;

                     numberOfProduct++;

 

                    case 2:

 

                    Console.WriteLine("2. Update existing product price");

                        break;

 

 

                    case 3:

 

                    Console.WriteLine("Enter the profit Percentage:");

                        int profitInPercent = int.Parse(Console.ReadLine());

 

                        for (int i=0; i<numberOfProduct; i++)

                       {

                        double salesProfits = (profitInPercent * retailPrices[i])/100;

                        Console.WriteLine("percentage :\t{0,8:c}", salesProfits);

                        }

                        Console.WriteLine("Products:");

                        

                        

                        break;

 

                    case 4:

 

                        Console.WriteLine("4. Calculate totals");

 

                        for (int j = 0; j<= retailPrices.Length ; j++){

 

                             retailPrices[j] += retailPrices[j + 1];

                            

                        

                        }

                        Console.Write("This is the tottal : ");

                        Console.WriteLine(retailPrices);

                            break;

 

                    case 5:

 

                        Console.WriteLine("5. Exit");

                         System.Environment.Exit (-1);     //to terminate the program

                        break;

                    default:

                        Console.WriteLine("Invalid input!!");

                        break;

 

                }

            }

            

         }

 


        public static string salesProfit { get; set; } 


        }

    }



Answers (1)