Sinux1

PS5Q5 cs 111

Mar 11th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int sum_num = 0;
  8.     int input;
  9.  
  10.     cout << "Enter a positive, non-zero integer\n";
  11.     cin >> input;
  12.     if (input>0)
  13.     {
  14.         for (int x = 1; x <= input; x++)
  15.             {
  16.             sum_num += x;
  17.             }
  18.         cout << "Sum of numbers from 1 to ";
  19.         cout << input << " is " << sum_num << endl;
  20.     }
  21.     else if (input == 0)
  22.     {
  23.         cout << "Hey, I said non-negative\n";
  24.     }
  25.     else
  26.     {
  27.         cout << "Hey, I said positive\n";
  28.     }
  29.  
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment