[ERROR] Expected primary-expression before '<=' token

I'm a beginner who is making a program for a science fair, the project involves ultrasonic sensors and I'm trying to find velocity using them. I've come across an error (in the case section of the switch part) that I cannot understand and find and so I would really appreciate it if someone could help. :slight_smile:

I've attached the code, here is the error;

Arduino: 1.6.12 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\hivam\AppData\Local\Temp\untitled1388721930.tmp\sketch_oct19a\sketch_oct19a.ino: In function 'void loop()':

sketch_oct19a:71: error: expected primary-expression before '<=' token

case <= 80000:

^

sketch_oct19a:85: error: expected primary-expression before '<=' token

case <= 120000 && >80000:

^

sketch_oct19a:85: error: expected primary-expression before '>' token

case <= 120000 && >80000:

^

sketch_oct19a:109: error: expected '}' at end of input

}

^

exit status 1
expected primary-expression before '<=' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Code.txt (1.73 KB)

The case keyword is followed by a constant. It is NOT followed by an operator. So, why do you have operators after the case keyword?

Do you have any idea what the range of values that you can store in an int? It would behoove you to look that up.

A switch statement with one case does not make sense.

:smiley: Thanks so much for the rapid response!

So, now that I cant use an operator, how else is it possible for me to carry out the "case" on a range of values? Must I use "if" statements?

Also, I guess I'll use long constants. :wink:

Appreciate the help!

Delta_G:
You'll use if statements for this.

Thanks! :slight_smile:

Must I use "if" statements?

No.

   switch(duration)
   {
      case 10040...20583:
         // Do something for this weird range
         break;
   }

But, there is NO point in having a switch statement with one case. Just use an if statement.