still trying to figure out while loop
I tried correcting the while loop... I am a step closer but not quite there....
The code I now am using is
#include<iostream.h>
#include<math.h>
main()
{
int firstnum, secondnum, answer;
cout<<"Please enter beginning term: ";
cin>>firstnum;
cout<<"Please enter ending term: ";
cin>>secondnum;
int total = firstnum;
while(firstnum<=secondnum)
{
cout<<answer<<" + ";
answer = firstnum++;
total +=answer;
}
cout<<" = "<<total;
}
When I run the program I get..
Please enter beginning term: 1 // i entered the number 1
Please enter ending term: 5 // i entered the number 5
5368726784 + 1 + 2 + 3 + 4 + = 16
I'm not sure why I am getting 5368726784.. any suggestions would be appreciated...
when the program is correct it should say 1 + 2 + 3 + 4 + 5 = 15
I apprecate the help so far... Any more would be even more appreciated.
Thank You
[email protected]
use this idea for the loop
int total=0
int temp=firstnum;
while(firstnum<=lastnum)
{
cout<<temp<<"+";
total=(total+temp);
temp++;
}
cout<<"="<<total;