0
So how would I do this like if less then 16 it would still say to young if I put in 5 as the var
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int age = 88; switch (age) { case 16: Console.WriteLine("Too young"); break; case 42: Console.WriteLine("Adult"); break; case 70: Console.WriteLine("Senior"); break; default: Console.WriteLine("The default case"); break; } } } }
5 Answers
+ 2
Use an if-else statement:
if (age < 16) {
// do something if under 16
} else {
// otherwise, do this
}
+ 1
A switch statement doesent check for bigger or smaller than it simply compares for equality.
If u dont want just equality than u should use an if statement.
0
and the same as the others
0
I'm only on the second lesson
0
thank you