Current x is undefined. You are going to want to have a sum variable outside of the for loop and set it equal to zero. Then just say something like sum += x; inside of your for loop though first you want to do something with x or you will have undefined behavior.
1 2 3 4 5 6
int sum = 0;
for( int i = 0; i < 10; ++i )
sum += i;
std::cout << "sum: " << sum << std::endl;
Thanks, I actually haven't learned that operator yet. My teacher is not very good, he just tells us to program something and doesn't teach us how. We spend most of our time looking on the internet learning how to program.
*edit well not really middle about a quarter of way down.
Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)
Compound assignment operators modify the current value of a variable by performing an operation on it. They are equivalent to assigning the result of an operation to the first operand:
expression equivalent to...
y += x; y = y + x;
x -= 5; x = x - 5;
x /= y; x = x / y;
price *= units + 1; price = price * (units+1);
and the same for all other compound assignment operators. For example:
1 2 3 4 5 6 7 8 9 10 11
// compound assignment operators
#include <iostream>
usingnamespace std;
int main ()
{
int a, b=3;
a = b;
a+=2; // equivalent to a=a+2
cout << a;
}
int sum = 0;
//for loop start
float term_val = coef[count] * pow( x , powe[count]) + term_val;
sum += term_val; //sum = sum + term_val;
//end for loop
*edit
One more thing to mention you kind of have two variables both named term_val. Technically they are in two different scopes so it should be fine but I would suggest just removing the float on line 6 and use the old tem_val variable.