Advertisement
Sinux1

PS7Q3.cpp

Apr 13th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  int inputx;
  8.  
  9.  
  10.     cout << "How many integers do you have? (Max 20)\n";
  11.     cin >> inputx;
  12.  
  13.     if(inputx > 0 && inputx < 21)
  14.     {
  15.         int num_array[inputx];
  16.  
  17.         for(int x = 0; x < inputx; x++)
  18.         {
  19.             cout << "Enter element for subscript " << x << endl;
  20.             cin >> num_array[x];
  21.         }
  22.  
  23.         cout << "Here are all of those numbers\n";
  24.  
  25.         for (int x = 0; x< inputx; x++)
  26.         cout << num_array[x] << endl;
  27.         int sum = 0;
  28.         for (int x = 0; x < inputx; x++)
  29.         {
  30.             sum += num_array[x];
  31.         }
  32.         cout << "The sum of these numbers is " << sum << endl;
  33.     }
  34.     else
  35.     {
  36.         cout << "You must enter a number in between 1 and 20\n";
  37.          exit(0);
  38.     }
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement