Hi. I have the following code which runs perfectly for every case except a negative number. This program outputs 1 if the argument in perfectSquare() is an fact a perfect square (and 0 otherwise). Can someone give me a conditional statement which will get the negative number scenario going? Thanks. Steve
Code:
#include<iostream>
using namespace std;
bool perfectSquare(int);
int main()
{
cout<<perfectSquare(0)<<endl;
return 0;
}
bool perfectSquare(int x)
{
int y;
for(y=0;y<=x;y++)
{
if(x==(y*y))
return true;
}
return false;
}