1. ## Rules for Comparison

I'm trying to error check against being able to put in a value less than .3 and more than .4. I'm having some problems though. When I enter a value outside of this range, the program accepts it. Are the rules for comparisons different when dealing with decimal or have I done something else wrong?

Thanks,
Vireyda

Code:
```		if(expenses[i].mileage_rate < 0.3 && expenses[i].mileage_rate > 0.4)
printf("\nThat mileage rate does not fall between \$0.30 and \$0.40.  Please try again.\n");```

2. You have your signs backwards...mileage_rate should be > than .3 and < .4

3. Actually, your signs are correct, but you should switch it to || instead of &&.

4. I've tried both suggestions, and I still can't get it to work for me. With the || instead of the &&, I end up in a never ending loop that rejects all input. With the reversed signs the program is still accepting everything. Any other suggestions?

Here is my most recent section of code:
Code:
```do
{
printf("Mileage Rate (between \$0.30 and \$0.40 per km):  ");
scanf("%f", &expenses[i].mileage_rate);

if(expenses[i].mileage_rate > 0.3 && expenses[i].mileage_rate < 0.4)
printf("\nThat mileage rate does not fall between \$0.30 and \$0.40.  Please try again.\n");

}while(expenses[i].mileage_rate > 0.3 && expenses[i].mileage_rate < 0.4);```

5. Eh my bad, I don't know what I was thinking...I believe jlou is correct, but I'm not sure what your problem is. Did you try this?
Code:
```{
printf("Mileage Rate (between \$0.30 and \$0.40 per km):  ");
scanf("%f", &expenses[i].mileage_rate);

if(expenses[i].mileage_rate < 0.3 || expenses[i].mileage_rate > 0.4)
printf("\nThat mileage rate does not fall between \$0.30 and \$0.40.  Please try again.\n");

}while(expenses[i].mileage_rate < 0.3 || expenses[i].mileage_rate > 0.4);```
Although based on my previous answer you probably shouldn't listen to me...

6. I should listen to you...Thank you. Your suggestion works perfectly.

Vireyda

7. actually, I've just done some testing of the program and I'm finding that it is excluding .4 when it should be included, but if I change the .4 to .41, the program starts including .4 and .41, when it should exclude .41. Any ideas?

Vireyda

8. You should show the code as you have it.
Code:
```if(expenses[i].mileage_rate < 0.3 || expenses[i].mileage_rate > 0.4)
printf("\nThat mileage rate does not fall between \$0.30 and \$0.40.  Please try again.\n");```
That code will not print the error message if the value is 0.4. I would assume that is what you want.

There is another possible reason for it being off. The precision of floating point numbers isn't exact, so it is possible that if you do calculations (like 2.0 / 5.0) you will get something that is not exactly equal to 0.4 (like 0.40000001). That might mess up your comparisons. To fix that, use an epsilon value to check for small errors like that:
Code:
```const double epsilon = 0.0001;
if (0.3 - expenses[i].mileage_rate > epsilon || expenses[i].mileage_rate - 0.4 > epsilon)
printf("\nThat mileage rate does not fall between \$0.30 and \$0.40.  Please try again.\n");```

9. actually, I've just done some testing of the program and I'm finding that it is excluding .4 when it should be included, but if I change the .4 to .41, the program starts including .4 and .41, when it should exclude .41. Any ideas?
in addition to > and <, you also have >= and <= :P(i assume you knew about these.)