Hi there ..
I wanna write a program that reads two numbers ( First & Last )
& Print the numbers between them & the sum ...
This is the code ..
Code:
#include <iostream>
#include <conio>
int main ()
{
int First , Last , sum = 0;
cout<< "Enter the First number : ";
cin>> First;
cout<< "Enter the Last number : ";
cin>> Last;
cout<< "\nThe numbers between " << First << " and " << Last << " are :";
cout<< "\n----------------------------------" << endl;
while ( First <= Last )
{
cout<< First << endl;
First++;
sum+=First ;
}
while ( First >= Last )
{
cout<< Last << endl;
Last++ ;
sum+=Last;
}
cout<< "----------------------------------" << endl;
cout<< "The sum = " << sum ;
getch ();
return 0 ;
}
There is no proplems when ( First >= Last ) ..
But there is when ( First <= Last ) ..
Also when I enter (-First & -Last ) or (+First & -Last) or ( -First & +Last)
.. The sum is wrong ..
& How can I solve the problem when ( First = Last)..
Any Help Greatly Appreciated..