In this assignment we had to use a loop to sum a number that the user chooses with every number in the middle of it and another maller number that the user chooses too. In order to do what mentioned, I would switch the part of the algorithm in charge of it.( the signs and mathematic algorithms)
Here’s my code:
https:/
or here too:
#include <iostream>
using namespace std;
int main (){
int x, y, z, ch, res, su;
do{
cout << “Introduce el número más chico.” << endl;
cin >> x;
cout << “introduce el número mayor.” << endl;
cin >> y;
if (x<y){
ch=0;
}
else {
cout << endl <<“escribiste los números de manera incorrecta, intenta de nuevo.” << endl;
ch=10;
}
} while (ch==10);
if(ch==0)
z=(y-x)+1;
su=0;
for (int i=0; i<z; i++){
res=(x+i);
su=su+res;
}
cout << “La suma de ” << x << ” hasta ” << y <<” es equivalente a ” << su;
return 0;
}
#WSQ07 by Juan Pablo Gonzalez Huezzo is licensed under a Creative Commons Attribution 4.0 International License.