so i stumbled upon a few 'challenge questions' and decided to have a go. it should be my level. so anyways
the question asked me to produce a code that makes me-
input 2 numbers.
the numbers get added ASWELL as the un numbers inbetween BUT excluding the numbers u input.
then display the result.
ie. if i input 5 and 2. the code should go ( 4+3)
if i input -4 and 5 the code should go(-3 + -2 + -1 + 0 + 1 + 2 + 3 + 4)
if i input 11 and 3 the code should go (10+9+8+7+6+5+4) *notice how it excludes 11 and 3?
it ignores ur input but adds numbers in between.
heres what i got so far
#include <iostream>
using namespace std;
int main( )
{
int total = 0;
int X, Y;
cout<<"please input 1st number ";
cin>>X;
cout<<"please input 2nd number ";
cin>>Y;
while(X>Y)
{total=X+Y+total;
X=X-1;
Y=Y+1;
}
cout<<"total of all integers in between is "<<total;
system("pause");
return 0;
}
but..this only works if X is greater than Y
what should i do to make it Y>X work as well?
ive tried using the 'else if' and 'switch case' but i seem to fail at that.
thanks in advance.