
Originally Posted by
Nimbuz
If I change the above to:
Code:
if (isdigit(iResponse) && iResponse >= 1 || iResponse < 10) {
printf("\nThank you\n");
} else {
printf("\nEnter a number between 1 and 10!\n");
}
..then it seems to work, but still, it takes 0 as valid whereas I want numbers >1 ? But I wonder why won't the first (posted above) condition work?
Many Thanks
Code:
if (isdigit(iResponse) && iResponse >= 1 || iResponse < 10)
What this translates to is
if
- iResponse is a digit and its value is greater than one
OR
- iResponse is greater than 10
print thank you.
Code:
(iResponse >= 1 || iResponse < 10)
and what your earlier one translats to is -
if
- iResponse is greater than or equal 1
OR
- iResponse is less than 10
print thank you.
What you want is -
Code:
(iResponse >= 1 && iResponse < 10)
if
- iResponse is greater than or equal 1
AND
- iResponse is less than 10
print thank you.