SilverhandX

numberarraymain.cpp

Feb 1st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include "NumberArray.h"
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int inputSize;
  8.  
  9.     cout << "How many spaces should the array have?" << endl;
  10.     cin >> inputSize;
  11.     cout << endl;
  12.  
  13.     Class1 c1(inputSize);
  14.  
  15.     double inputNumber;
  16.  
  17.     for (int counter = 0; counter < inputSize; counter++)
  18.     {
  19.         cout << "Please enter a value for space " << counter + 1 << " in the array.\n";
  20.         cin >> inputNumber;
  21.         c1.storeNumber(inputNumber, counter);
  22.         cout << endl;
  23.     }
  24.  
  25.     double inputNumber1;
  26.     int inputSlot1,
  27.         inputSlot2;
  28.     int menuChoice;
  29.  
  30.     for (int counter1 = 1; counter1 < 2;)
  31.     {
  32.         cout << "Enter a number to choose an action\n";
  33.         cout << "1 Store a number\n";
  34.         cout << "2 Retrieve a number\n";
  35.         cout << "3 View highest number\n";
  36.         cout << "4 View lowest number\n";
  37.         cout << "5 View average of numbers\n";
  38.         cout << "6 Exit program\n";
  39.  
  40.         cin >> menuChoice;
  41.  
  42.         if (menuChoice == 1)
  43.         {
  44.             cout << endl;
  45.             cout << "Which space would you like to store the number in?\n";
  46.             cin >> inputSlot1;
  47.             inputSlot1 -= 1;
  48.             cout << endl;
  49.            
  50.             cout << "What number would you like to store?\n";
  51.             cin >> inputNumber1;
  52.             cout << endl;
  53.  
  54.             c1.storeNumber(inputNumber1, inputSlot1);
  55.  
  56.             inputSlot1 +=1;
  57.             cout << inputNumber1 << " has been stored in space " << inputSlot1 << ".\n\n";
  58.         }
  59.  
  60.         else if (menuChoice == 2)
  61.         {
  62.             cout << endl;
  63.             cout << "Which space would you like to retrieve a number from?\n";
  64.             cin >> inputSlot2;
  65.             inputSlot2 -= 1;
  66.             cout << endl;
  67.  
  68.             cout << "The number is " << c1.getNumber(inputSlot2) << ".\n\n";
  69.         }
  70.  
  71.         else if (menuChoice == 3)
  72.         {
  73.             cout << endl;
  74.             cout << "The highest number in the array is " << c1.getHighest() << ".\n\n";
  75.         }
  76.  
  77.         else if (menuChoice == 4)
  78.         {
  79.             cout << endl;
  80.             cout << "The lowest number in the array is " << c1.getLowest() << ".\n\n";
  81.         }
  82.  
  83.         else if (menuChoice == 5)
  84.         {
  85.             cout << endl;
  86.             cout << "The average of all numbers from the array is " << c1.getAverage() << ".\n\n";
  87.         }
  88.  
  89.         else if (menuChoice == 6)
  90.         {
  91.             counter1 = 2;
  92.             cout << endl;
  93.         }
  94.     }
  95.  
  96.    
  97. }
Add Comment
Please, Sign In to add comment