When given input, my while loops print one time extra before closing its loop. For example, 8 7 38 3 -5 -1 q is my input that prints out
Provide 6 integer coefficients for the brute force equation solver: Solution found: x = 3, y = 2
Run program again? Type 'q' to quit or any other key to continue:
Provide 6 integer coefficients for the brute force equation solver: Solution found: x = 3, y = 2
Run program again? Type 'q' to quit or any other key to continue:
When it should end after the first iteration. Can anyone help me out on this? My code is pasted below
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
int main(void)
{
//Equations should be a1x + b1y = c2 and a2x + b2y = c2
int a1, b1, c1, a2, b2, c2, x, y;
char input;
bool solFound = false;
bool runAgain = true;
//brute force x and y [-10, 10]
while (runAgain == true)
{
printf("Provide 6 integer coefficients for the brute force equation solver: ");
scanf("%d %d %d %d %d %d", &a1, &b1, &c1, &a2, &b2, &c2);
for (x = -10; x<=10; x++)
{
for (y = -10; y<=10; y++)
{
if (a1*x + b1*y == c1 && a2*x + b2*y == c2)
{
printf("\nSolution found: x = %d, y = %d\n\n", x, y);
solFound = true;
runAgain = false;
}
}
}
if (solFound != true)
{
printf("No solution found\n\n");
runAgain = false;
}
scanf("%c", &input);
printf("Run program again? Type 'q' to quit or any other key to continue:");
if (input != 'q')
{
runAgain = true;
}
printf("\n\n");
}
} ```