我对 C 和编程还很陌生,而且我一直被卡住。我正在通过一个程序来练习,只是增加了它的复杂性。
与这里提出的其他一些问题相比,该程序相当简单。我要做的就是输入一个数字,然后说出它是小于还是大于五。我最近添加了一个菜单和一个 Do While 循环。这是下面的代码。
#include <stdio.h>
void main ()
{
int ANumber;
bool Determine = 1;
int MenuChoice;
printf("1) Enter a number." "\n2) Exit.\n");
printf("\nPlease choose an option from the menu above - ");
scanf("%d", &MenuChoice);
if (1 == MenuChoice) {
do {
printf("\nPlease enter a number that is between 0 and 10 - ");
scanf("%d", &ANumber);
if (ANumber == 5)
printf("The number you entered is 5.\n");
if (ANumber >= 6)
printf("The number you entered is larger than 5.\n");
if (ANumber <= 4)
printf("The number you entered is smaller than 5.\n");
getchar();
printf("Would you like to continue? 1 = Yes OR 0 = No - ");
scanf("%d", &Determine);
return;
} while (true == Determine);
if (false == Determine) {
return;
}
}
if (2 == MenuChoice)
return;
}
主要问题是大部分代码都可以正常工作。
当我想退出循环时出现问题:
while (true == Determine);
if (false == Determine) {
return;
}
当我在程序中输入 0 时出现此错误:
Run-Time Check Failure #2 - Stack around the variable 'Determine' was corrupted.
我可以请我帮忙说明什么是错误的以及此错误消息的含义吗?
谢谢