// You need this for cin and cout
#include <iostream>
// You need this for sqrt
#include <cmath>
// You need this for lots of stuff
using namespace std;
// Returns true if number is a perfect square
bool IsSquare (int num)
{
// Calculate the square root of num
// Casting to an int truncates any decimal parts
int sqrt_num = sqrt(num);
// If the previous line didn't truncate and digits
// then the number must be a perfect square.
// If the square root squared equals the original
// number it is a perfect square!
return sqrt_num*sqrt_num == num;
}
int main()
{
// Perfect squares only work on integers
int num;
// Loop while num
while(true){
// Ask for number
cout << "Enter number to determine if it is a perfect square: \n";
cin >> num;
// Stop if number is less than 1
if(num < 1) break;
// Number was a square
if (IsSquare(num)) cout << num << " is a square\n";
// Number wasn't a square
else cout << num << " is not a prefect square\n";
}
return 0;
}