by Therese
by Therese

Hello!

I just did #WSQ07, it took me about fifteen minutes… But I had an error, I missed a key, so the program was not doing what I wanted to. Ken helped me realize that and that was it! I think that if the user typed the bigger number first, I would use an if to fix it.

Here’s my code:

#include <iostream>
using namespace std;
int main ()
{
int v1, v2;
int sum=0;
cout<< “Enter the lower bound of the range:”;
cin>> v1;
cout<< “Enter the upper bound of the range:”;
cin>> v2;
int number=v1;
while (number<=v2){
sum= sum+number;
number++;
}
cout << “The inclusive sum is:”<<sum<<endl;
return 0;
}

CC BY 4.0 Sum of numbers by Mferflores is licensed under a Creative Commons Attribution 4.0 International License.