#include<iostream>
#include<cmath>
using namespace std;
int main() {
int n;
cout<<"Please enter an integer :"<<endl;
cin>>n;
****************************
This is my objective :
Write a program which reads an integer n entered by the user and prints true if n is a perfect square and false if it is not. Im not sure as to how to go about doing this with an If statement / boolean operations and I'd appreciate all the help I can get :)
*I know how to do an IF statement and how to use booleans. I'm just not clear on how to get it to check to see if it is a perfect number or not*
Thanks
#include <iostream>
usingnamespace std;
int main()
{
int x;
int check=0;
cout<<"Enter a number: ";
cin>>x;
for(int i=0;i<99999999;i++)
if(x==i*i)
{
cout<<"\nYes!, "<<x<<" is a perfect square!";
check=1;
break;
}
if(check!=1)
cout<<"\nNo "<<x<< " is not a perfect square!";
cin.ignore();
cin.get();
}
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int x;
int check=0;
cout<<"Enter a number: ";
cin>>x;
for(int i=0;i<99999999;i++)
if(x==i*i)
{
cout<<"\nYes!, "<<x<<" is a perfect square!";
cout<<"\n"<<sqrt(x)<<" is it's square root!";
check=1;
break;
}
if(check!=1)
cout<<"\nNo "<<x<< " is not a perfect square!";
cin.ignore();
cin.get();
}