I have created a program that asks for two numbers between 100 & 150. Also the difference between these numbers must be less than or equal to 10. I run the program but it doesn't end it continually loops even when I enter the correct values.
#include <stdio.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE !FALSE
int main(void)
{
double a, b;
double epsilon = 10.000000001;
int flag_1, flag_2;
flag_1 = FALSE;
flag_2 = FALSE;
do
{
printf("Enter in two values between 100.0 & 150.0\n");
printf("The difference between each value must be less than or equal to 10.0\n\n");
printf("Enter in value a: ");
scanf("%lf", &a);
printf("Enter in value b: ");
scanf("%lf", &b);
if (((a < 100.0)||(a > 150.0))||((b < 100.0)||(b > 150.0)))
{
printf("Error Enter between 100.0 & 150.0\n\n");
flag_1 = TRUE;
}
else if (((a - b) > (epsilon))||(((a - b)*(-1)) > (epsilon)))
{
printf("Error\n\n");
flag_2 = TRUE;
}
else
{
printf("Values a & b are: a = %lf, b = %lf\n\n", a, b);
}
}while((flag_1 == TRUE)||(flag_2 == TRUE));
system ("pause");
return 0;
}
%fin all theprintfs. Also, try addingflag_1 = FALSE; flag_2 = FALSE;at the start of thedo...whileloop.flag_1/2 == FALSE;at inside thedoloop before you check the validity of the items.