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; } } } }

1st Sep 2016, 9:11 PM
37Produtuction
37Produtuction - avatar
5 Antworten
+ 2
Use an if-else statement: if (age < 16) { // do something if under 16 } else { // otherwise, do this }
1st Sep 2016, 9:52 PM
Liam
Liam - avatar
+ 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.
10th Sep 2016, 4:25 PM
abdiyee idris
abdiyee idris - avatar
0
and the same as the others
1st Sep 2016, 9:12 PM
37Produtuction
37Produtuction - avatar
0
I'm only on the second lesson
1st Sep 2016, 9:12 PM
37Produtuction
37Produtuction - avatar
0
thank you
1st Sep 2016, 9:54 PM
37Produtuction
37Produtuction - avatar