-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?

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123
  • 10
    `if ( timeramount >5 && timeramount <10 )` I suggest you to read the (very) basics before posting questions like this. – Maroun Mar 29 '13 at 20:46
  • 1
    "tried Google, found a few sites on maths but not on something like this" - you're kidding, right? – Daniel Kamil Kozar Mar 29 '13 at 20:48
  • thanks for your comments , i am used to working in BASIC , well 20 years ago so i know what i need to do , but the OS is very different..give ppl a break , im sure when you started you asked the 'basic' questions..its learning a new skill... –  Apr 04 '13 at 09:36

1 Answers1

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.

Community
  • 1
  • 1
Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123