double zerocount = 0, count = 0;
system("pause");
cout << "Initial display of the pyramid:" << endl << endl;
//Displaying the pyramid using the function "display"
display(np);
//counting Zeros before solving
zerocounter(np);
cout << endl << endl << endl; //putting space after the pyramid
cout << "The number of zeros starting the pyramid is: " << zerocount << endl;
system("pause");
while (zerocount != 0) //Begin giant while loop
{
//solver in the while loop using the "solver" function
solver(np);
//Displaying the pyramid using the function "display" in the while loop
display(np);
cout << endl << endl << endl; //putting space after the pyramid
//Zero counter in the while loop using the function "zerocounter"
zerocounter(np);
count++;
cout << "The number of passes through the pyramid so far is: " << count << endl << endl;
system("pause");
};
cout << "Thanks for playing the pyramid game!" << endl;
system("pause");
return 0;
}
double zerocounter(int pzc[7][7])
{
int i, j;
double zerocount = 0;
for (i = 0; i < maxr; i++)
{
for (j = 0; j < maxc; j++)
{
if(pzc[i][j] == 0)
zerocount++;
}
}
cout << "The number of zeros remaining is: " << zerocount << endl;
return zerocount;
}
void display(int pd[7][7])
{
int i, j;
for (i = 6; i >= 0; i--)
{
cout << endl;
for (j = 0; j < maxc; j++)
{
if (pd[i][j] == -1)
cout << " ";
else
cout << setw(6) << pd[i][j];
}
}
return;
}
int solver(int ps[7][7])
{
int i, j;
for (i = 6; i >= 0; i--)
{
for (j = 0; j < 6; j++)
{
if (ps[i][j] != -1 && ps[i + 1][j + 1] == 0 && ps[i][j + 1] != 0 && ps[i][j] != 0)
ps[i + 1][j + 1] = ps[i][j + 1] + ps[i][j];
if (ps[i][j] != -1 && ps[i + 1][j + 1] != 0 && ps[i][j + 1] == 0 && ps[i][j] != 0)
ps[i][j + 1] = ps[i + 1][j + 1] - ps[i][j];
if (ps[i][j] != -1 && ps[i + 1][j + 1] != 0 && ps[i][j + 1] != 0 && ps[i][j] == 0)
ps[i][j] = ps[i + 1][j + 1] - ps[i][j + 1];
}
}
return ps[7][7];
}
For some reason after the pyramid is solved, it will display as having no zeros left but it will continue to run through the while loop.
You never seem to modify the value of "zerocount", so i'm not sure why you think this line: while (zerocount != 0)
would ever test a different condition than the first test that gets you inside the loop.
no problem mate.
one other thing: why have you declared zerocount as a double inside that function? Seeing as you only increment it, i'd turn it into an integer, and also make the function return an integer.