Advertisement
Guest User

Test

a guest
Mar 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*
  6.     COS 132 Activity 1:
  7.  
  8.     Remember that Arrays are zero indexed. This means that the first element of the array is reffered to as MyArray[0].
  9.     Therefore when declaring an array with n elements, we declare it as MyArray[n-1].
  10.     Done by Matthew Kelly.
  11. */
  12.  
  13. int main()
  14. {
  15.     // Declaring Variables.
  16.     int Choice;
  17.     int Number;
  18.     int MyArray[4];
  19.  
  20.     // Getting Values.
  21.     cout << "Enter a number: ";
  22.     cin >> Number;
  23.  
  24.     cout << "Enter a choice: ";
  25.     cin >> Choice;
  26.  
  27.     switch(Choice)
  28.     {
  29.         case 1:
  30.             // Case 1:
  31.             for (int i = 0; i < 5; ++i)
  32.                 MyArray[i] = -5 + Number;
  33.  
  34.             break;
  35.  
  36.         case 2:
  37.             // Case 2:
  38.             for(int i = 0; i < 5; ++i)
  39.                 MyArray[i] = i - Number;
  40.  
  41.             break;
  42.  
  43.         case 3:
  44.             // Case 3:
  45.             for (int i = 0; i < 5; ++i)
  46.                 MyArray[i] = 5 * (7 * (i + 1));
  47.  
  48.             break;
  49.     }
  50.    
  51.     // Outputting each element of the array.
  52.     for(int i = 0; i < 5; ++i)
  53.         cout << MyArray[i] << " ";
  54.  
  55.     cout << endl;
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement