Sum of numbers

 

In this program, we asked the user for a range of numbers and the program sum the numbers in between.

Captura1.PNGCaptura2.PNG

If you want to make improvements or modifications, here is the code for you to copy and paste it anywhere.

#include <iostream>
#include <cmath>
using namespace std;
int sumanumeros(int a, int b){
int suma,contador;
suma=0;
contador=a;
if(a>b){
cout<<“The first number must be smaller than the second”<<endl;
return 0;
} else{
if(a==b){
cout<<“There is no range between the numbers”<<endl;
return 0;
} else{
do{
sum=sum+counter;
counter++;
}while(counter<=b);
return sum;
}
}
}
int main(){
int min,max,result;
cout <<“Type in two numbers to obtain the sum of their range”<<endl;
cout <<“First number”;
cin >> x>> endl;
cout<<“Second number”<<;
cin>> max;
cout<<endl;
result= sumanumeros(min,max);
if(result>0);{
cout<<“Result “<<result<<endl;
}
return 0;
}

One thought on “Sum of numbers

  1. Hola, lo probé pero tienes algunos errores que por lo menos en mi computadora salieron, por ejemplo que declaras “contador” y luego lo usas como “counter” y también me aparece que no declaraste la variable “x”. Saludos.

    Like

Leave a comment