while loop - still need help
I have been working on a problem to enter the first term then a second term.... then add all of the numbers
for example..
enter first term: 1
enter second term: 5
output
1+2+3+4+5 = 14
I was able to get that to work correctly...
now I am trying to do the second half of the program...
to output
1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 + 5*5*5 = answer
this is what i have so far... I think I have the right idea but something like a bracket in the wrong place or maybe too many places
#include<iostream.h>
#include<math.h>
main()
{
int firstnum, secondnum, answer;
int total = 0;
int total2 = 0;
cout<<"Please enter beginning term: ";
cin>>firstnum;
cout<<"Please enter ending term: ";
cin>>secondnum;
while(firstnum<=secondnum)
{
{
cout<<firstnum<<" + ";
total=(total+firstnum);
firstnum++;
}
cout<<" = "<<total<<"\n";
{
cout<<firstnum<<" * " << firstnum<<" * "<<firstnum;
total2 = (firstnum * firstnum * firstnum);
firstnum++;
}
cout<<" = "<<total2<<"\n";
}
}
when i compile I get an error.... expecting a bracket....
suggestions would be appreciated.
thank you
[email protected]
still having looping problems
I am still trying to make a program that:
Enter first term: 1
Enter second term: 4
Output:
1 + 2 + 3+ 4 = answer
1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 = answer
This is the code that I have:
#include<iostream.h>
#include<math.h>
main()
{
int firstnum, secondnum, answer;
int total = 0;
int total2 = 0;
cout<<"Please enter beginning term: ";
cin>>firstnum;
cout<<"Please enter ending term: ";
cin>>secondnum;
while(firstnum<=secondnum)
{
{
cout<<firstnum<<" + ";
total=(total+firstnum);
firstnum++;
}
cout<<" = "<<total<<"\n";
{
cout<<firstnum<<" * " << firstnum<<" * "<<firstnum;
firstnum++;
}
total2+= (firstnum * firstnum * firstnum);
cout<<" = "<<total2<<"\n";
}
}
But instead when I run the program I get:
Please enter beginning term: 1
Please enter ending term: 4
1 + = 1
2 * 2 * 2 = 27
3 + = 4
4 * 4 * 4 = 152
Any suggestions would be really appreciated.
Thank You