I am fairly new to C and programming and I keep on getting stuck. I'm practising by having one program and just adding more complexity to it.
The program is fairly simple, when compared to some of the other questions asked here. All I want to do is to input a number and then say if it is less than or greater than five. I've recently added a menu and a Do While loop. This is the code below.
#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;
}
The main problem is that the majority of the code works fine.
The problem occurs when I want to exit the loop :
while (true == Determine);
if (false == Determine) {
return;
}
When I enter 0 into the program this error comes up :
Run-Time Check Failure #2 - Stack around the variable 'Determine' was corrupted.
May I please have some help indicating what is wrong and what this error message means?
Thanks