#WSQ04

i feel so happy because this is actually the first i solve myself without asking for help, even if it is a berry simple and basic program i feel like finally i’m making some kind of progress, there are some shots of my write programcaptura-de-pantalla-161Captura de pantalla (165).png   when i was working on the program i figure out that the easiest way to solve this kind of program was just to make couples of numbers , but when i run the program i got stuck, because if only work if i’ve got a pair amount of numbers but if i try with something like numbers from 1 to 9 or something like that my program will give me a wrong answer, so i put a bunch of useless couts in the middle of my bucle, hopping that that will help me figure out what was wrong, and i stay stuck during a couple of days with the answer right in front of my eyes, notice that i use two values to sum, one called comienzo and another called proceso, and when i run my program the way was write with a non pair amount of numbers at some point, most specifically just before the program ends  proceso and comienzo were the same number, so i just got to put an if that rest the middle number once it got summed twice to get te righ answer without modify in a significantly way mi program, as usual i here are a couple of screen shots of how it works

captura-de-pantalla-168Captura de pantalla (171).png as usual i will give mi code in text format, just because it its becoming a tradition to mention in my blogs, and in case you want to copy it i suggest to erase the bunch of crappy useless couts i put in the middle

#include
using namespace std;

int main()
{
int limiteinferior;
int limitesuperior;
int comienzo;
int proceso;
int limite;
int suma;
int total;

cout<<“we will calculate the sume of integers in the range you provide”<<‘\n’;
cout<<“please give us the lower bound:”<<‘\n’; cin>>limiteinferior;
comienzo=limiteinferior;
cout<<“please give us the upper bound:”<<‘\n’; cin>>limitesuperior;
limite=limitesuperior;
proceso=limite;
while(comienzo<=proceso)
{
suma=comienzo+proceso;
cout<<“comienzo”<<comienzo<<‘\n’;
cout<<“proceso”<<proceso<<‘\n’;
cout<<“limite”<<limite<<‘\n’;
cout<<“suma”<<suma<<‘\n’;
cout<<“total”<<total<<‘\n’;
comienzo=comienzo+1;
proceso=proceso-1;

total=total+suma;
if(comienzo==proceso)
{
total=total-proceso;
}
}
cout<<” the sum from “<< limiteinferior <<” to “<< limitesuperior << “(inclusive) is: “<<total<<‘\n’;
return 0;
}

as always, tanks for reading.

Leave a comment