Square root and while loop trouble.

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 using namespace 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=r2
a-b=s2
for some integers r and s.

Solving for a and b gives
a=(r2+s2)/2
b=(r2-s2)/2
so just choose all pairs r and s (both even or both odd) to give a and b in the given range.
Topic archived. No new replies allowed.