当给定输入时,我的 while 循环在关闭它的循环之前额外打印一次。例如, 8 7 38 3 -5 -1 q 是我打印出来的输入
为蛮力方程求解器提供 6 个整数系数: 找到的解:x = 3, y = 2
再次运行程序?键入“q”退出或任何其他键继续:
为蛮力方程求解器提供 6 个整数系数: 找到的解:x = 3, y = 2
再次运行程序?键入“q”退出或任何其他键继续:
当它应该在第一次迭代后结束。谁能帮我解决这个问题?我的代码粘贴在下面
#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");
}
} ```