Hi, I have to find whether or not two numbers when added and subtracted together make perfect squares up to a user inputted integer. I have searched everywhere but can't seem to find the answer below is the code I have made so far. I can only use the two libraries for this so anything I find online hasn't been of much help. I can also use isdigit, isalpha, cin.clear, and cin.ignore. As well as whenever they're done it must repeat and type an error after the input. I've tried to do this for days now and i'm at my wits end with this. I'm still relatively new to coding so i'm still figuring this out but was wondering if anyone on here could help.
usingnamespace std;
int main()
{
cout<<"Square numbers are certain pairs of numbers when added together \n""gives a square number and when subtracted also gives a square number.\n""This program displays all the pairs of square numbers.";
int number_input;
double second_number;
double first_number;
char answer;
double uppersquare = sqrt((double)(first_number+second_number));
double lowersquare = sqrt((double)(first_number-second_number));
do
{
cin.clear();
cout << "\n\n Enter a number ----> : "; cin >> number_input;
if (isalpha(number_input)==1)
cout << "Invalid choice, Must enter Y, y or N,n\n""Would you like to enter another number , Enter Y or y , N or n --->"; cin>> answer;;
cout << "The square pair numbers are:-" <<endl;
cout << "N\t\tP\t\tN+P\t\tP-N" <<endl;
cout << "----------------------------------------" <<endl;
while(second_number <= number_input)
{
second_number++;
first_number=0;
for(first_number < second_number;first_number++;)
{
if (uppersquare == isdigit(uppersquare) && lowersquare == isdigit(lowersquare))
continue;
}
cout<<first_number<<second_number<<uppersquare<<lowersquare;
}
cout<<"Would you like to enter another number , Enter Y or y , N or n --->"; cin>> answer;
}
while ((answer != 'N')||(answer != 'n'));
return 0;
}
No idea why isdigit() or isalpha() would be of any use to you.
You appear to be looking for numbers a and b such that
a+b=r^{2}
a-b=s^{2}
for some integers r and s.
Solving for a and b gives
a=(r^{2}+s^{2})/2
b=(r^{2}-s^{2})/2
so just choose all pairs r and s (both even or both odd) to give a and b in the given range.