Double to int warning.

I'm getting a warning that my variable is being converted to an int from a double, however, I see nothing in my code which would indicate a floating point number is being used.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int x;
	int sum = 0;
	int sumsq;


	for (x = 1; x <= 100; x++)
	{
		sum += pow(x, 2);
	}

	sumsq = pow(sum, 2);
	cout << (sumsq - sum);
	return 0;
}


Lines 14 and 17 seem to be at fault, but integer power functions should return an integer.
Last edited on
Not according to this: http://www.cplusplus.com/reference/clibrary/cmath/pow/

EDIT: too late!
Last edited on
You also shouldn't be using pow to square things. It's overkill. Just square them manually:

1
2
3
// sum += pow(x, 2);  <- bad

sum += x*x;  // <- good 

Topic archived. No new replies allowed.