0

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

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; } 

        }
    }{


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; } 

    }
}
2
Contributors
1
Reply
13
Views
2 Years
Discussion Span
Last Post by Suzie999
0

You have an ebedded class it seems, and two Main(), along with non declared variables being used.

Have a look at this, see if it's any better.

Sorry, I forgot to comment what I did as I was doing it.

namespace daniwebtestconsoleapp
{
    class Program
    {
        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 numberOfProduct = 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());

                        }

                        numberOfProduct++;
                        break;


                    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; }

    }

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.