Advertisement
Stosswalkinator

Multiple Input Range Sum

Sep 25th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. int main() {
  3.     int v1 = 0, v2 = 0, sum = 0;
  4.     std::cout << "Enter two numbers: " << std::endl;
  5.     std::cin >> v1 >> v2;
  6.     if (sum = 0) {
  7.         while (v1 < v2)
  8.             sum += v1;
  9.             ++v1;
  10.     } else {
  11.         while (v1 > v2)
  12.             sum -= v1;
  13.             --v2;
  14.     }
  15.     std::cout << "Sum is: " << sum << std::endl;
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement