Hello every body....i am having a little problem...i have written a program in c++ which takes two integers i and j and compute the sum of the numbers between them....but when i use the while loop to re enter the values...the answer becomes wrong for the same value....the program code is below
//write a program to read two numbers i and j and compute the sum of all the numbers between
//i and j and display the result
#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
int i=0,j=0,m=0;
char opt='y';
while (opt=='Y' || opt=='y')
{
cout<<"Enter the value of i = ";
cin>>i;
cout<<"\nEnter the value of j = ";
cin>>j;
for(i;i<j-1;)
{
i=i+1;
cout<<"\t"<<i;
m = m + i;
}
cout<<"\nThe sum of the numbers between i and j is = "<< m;
cout<<"\n\n\nDo you want to check more value [y/n] = ";
cin>>opt;
system("cls");
}
getch();
}
when i enter 1 and 4 for i and j respectively, i get correct ans as 5...but when i repeat the program code by using while loop...the answer if different for the same integers 1 and 4...thanks in advance