A help please

Hi..
i did this program but it gave me wrong in this step:sum=sum+pow(i&2);
So What is the mistake?
Thanks all!
#include <iostream>
#include <cmath>
using namespace std;
int main()
{ int m;
int num;
int sum=0;
cout<<"Enter a postive integer";
cin>>m;

for (int i=1;i<=num;i++)
sum=sum+pow(i&2);
cout<<"the sum of the first"<<num<<"squares is"<<sum<<endl;
cin>>m;
return 0;
}
The pow function takes two parameters. You appear to be trying to hand it i&2 which is the int i bitwise ANDed with the number 2. I suspect you don't know what that means, so it's likely you didn't intend that at all.

Try this instead:
sum=sum+pow(i,2);

If you're trying to output the first num squares, shouldn't
cin>>m;
be
cin>>num;?
Last edited on
I think it should be
sum=sum+pow(i,2);
Thanks all but it gave me the same mistake!!
try sum=sum+pow(i,2.0);
I guess you didn't use @Moschops advice.

I think your m variable is useless (unless you intend to expand your program and give it a role) so you can safely use num for all cases.

Do you use cin>>m; before return just to keep console running? If so you can use num istead and also see
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.