-4

I want to compare a value against the two ends of the range. This is how my code looks like:

if ( timeramount >5 && <10 )...do some stuff...

So my application needs to know if timeramount is greater than 5 but less than 10.

Can anyone help?

4

1 回答 1

2

Logical operators such as &&, || etc. take two operands. Those operands must be expressions. < 10 is not a valid expression, as it is missing one operand ("what is less than 10?").

To express in C what in natural language you described as "if timerarount is greater than 5 but less than 10", you must be more verbose:

if (timeramount > 5 && timeramount < 10) {
    /* if timeramount is greater than 5 AND timeramount is less than 10 */
    ;
}

I suggest you grab a good introductory book on C in order to learn the basics of the language. Kernighan & Ritchie's "The C Programming Language" is a good start but you can consult this question.

于 2013-03-29T20:54:53.133 回答