i am writing a program to find all integers that have 5 perfect squares within 30 of them... here is what i have so far:
#include <iostream>
using namespace std;
int range[60];//since "within 30" means to more and 30 less
void integer(int testInteger) //testInteger is the integer to use to create an array of integers 30 greater than and 30 less than it
{
int locationInRange = 0;//default for location in the array to be filled in (range[60])
int upperBound = testInteger + 30;//30 more
int lowerBound = testInteger - 30;//30 less
for (lowerBound; lowerBound <= upperBound; lowerBound++)//"lowerBound" is used here because the array fills from last term to first term (i.e. -30 to 30)
{
range[locationInRange] = lowerBound;//every location in the array has a corresponding and incremented integer it originates from
locationInRange++;
}
}
int main()
{
int n = 0;
int perfectSquares[6];//size doesnt need to be bigger than 6 because past 6^2 there are no five consecutive perfect squares with a range of less than or equal to 30
int locationOfSquare = 0;
for (n; n <= 6; n++)
{
perfectSquares[locationOfSquare] = n * n;// makes array of position n have value of n^2: creates the array of perfect squares
locationOfSquare++;
}
int count = 0;
for (int k = -14; k <= 36; k++)//loop through values -14 <= k <= 36 because of inequality (n+5)^2-n^2 > 30 and upper bound
{
integer(k);
for (int i = 0; i <=60; i++)//loop through range[60]
{
for (int j = 0; j <= 6; j++)//loop through perfectSquares[6]
{
int qualification;
if (range[i] == perfectSquares[j])//find intersecting elements of range[60] and perfectSquares[6] and count
{
count++;
qualification = 1;
}
while (qualification == 1)
{
cout << range[k] << endl;//display integers that work
}
}
}
}
}
the part that i have a problem with is counting. im not sure how to do it in a way that gives me only the right integer values.