-5

how do I check if a specific integer is within a specific range?

What I mean is if int total is between 20 and 39 (30) it doesn't go to 0-19 neither 40-69

iehrlich
  • 3,572
  • 4
  • 34
  • 43
Sport
  • 55
  • 8
  • `if (20 <= total && total <= 39)` ? Are you just asking how to compare numbers? – David Jun 27 '17 at 15:05
  • Use comparison operators such as `<`, `>`, `<=`, and `>=`. Don't use `Enumerable.Range(20, 30).Contains(n)`. – 15ee8f99-57ff-4f92-890c-b56153 Jun 27 '17 at 15:06
  • 1
    What exactly are you having problems with? Do you not know how to compare two numbers? do you not know how to check if a number is in a bounded range? Is it checking against multiple ranges that is giving you problems? Do you think you're doing it right but its giving the wrong results? You need to be more specific about what your problem is. And also show us the code you've tried! – Chris Jun 27 '17 at 15:07

1 Answers1

0
if (total >= 20 && total <= 39) {
    //do some stuff
}
Jay Buckman
  • 581
  • 5
  • 18