mercredi 19 avril 2017

Array data lost during Switch and If-Else loops/Statments C++

I'm currently trying to structure a program to give the user the option on which process to proceed with, after inputting array information. When I compile this without Switch Statments and If-Else loops, all my calculations and outputs are correct. When I tried structuring this to Switch Statements, I'd get exponential results on Sum calculations, as well as Functions programmed to show the values of the program entered. The problem being, where do these go and why does this not happen to all of the Switch / If-Else statements? I've entered a portion of my program including the sum (to keep it relevant to the question) below. Even if there's no feedback upon the code, a clarification would be greatly appreciated! :

    const int ARRAY_SIZE = 10;
    int myList[ARRAY_SIZE];

   cout << "\n\t\tLab Twelve Menu\n\n"
        << "1. Find the Sum of the numbers entered.\n"
        << "2. Find the Minimum of the values entered.\n"
        << "3. Find the Maximum of the values entered\n"
        << "4. Show the Values \n"
        << "5. Quit menu\n"
        << "\n"

        << "Enter your choice: ";
    cin >> choice;


    while (choice < Find_Sum || choice > quit_menu)
    {
     cout << "Please enter a valid menu choice: ";
     cin >> choice;
    }
     else if (choice == 1)
        {
            //Finding the sum
            cout << "Please enter 10 values seperated by spaces \n";
            cin >> myList[0];
            for (int i = 0; i < ARRAY_SIZE; i++)
            {
                sum = sum + myList[i];
             }
            cout << endl;
            cout << "The sum of all these numbers is: " << sum << endl;
            cout << endl;
        }

Aucun commentaire:

Enregistrer un commentaire