General series add just having problem on only one part

Write your question here.

I want to add the series numbers except square numbers
For example,if n = 10, Add : 1+2+3+5+6+7+8+10 = 42(except 4 and 9)
but I got problem to except the square number by using continue statement.
Please help me.



#include <iostream>
using namespace std;

int main()
{
int n;
cout<<"enter number to add"<<endl;
cin>>n;

int counter=0;
int sum=0;



while(counter<n)
{
counter++;
if(counter==(n*n))
continue;
sum+=counter;
}
cout<<sum<<endl;

return 0;
}
Last edited on
Wrong test. If n==10, then n*n==100. Counter is hardly ever that, is it?

You must test for counter being a square of integer by some other way.
Topic archived. No new replies allowed.