0

How do i solve the 6th hidden case in Go switch lesson

Go course , the switch lesson requires i solve a code coach problem, i did and my code worked in all but one hidden case , Here's the code: package main import "fmt" func main() { var f int fmt.Scanln(&f) switch { case f < 20: fmt.Println("Infrasound") case f > 20000: fmt.Println("Ultrasound") default: if 20 <= f && f <= 20000 { fmt.Println("Audible") } else { fmt.Println("Wrong input") } } }

7th Apr 2023, 6:37 PM
محمد عبد الله حطيبة
محمد عبد الله حطيبة - avatar
4 ответов
0
Ok so the problem was that "Wrong Input" is not the same as "Wrong input" ... Kill me
8th Apr 2023, 5:15 PM
محمد عبد الله حطيبة
محمد عبد الله حطيبة - avatar
+ 1
**🇦🇪|🇦🇪** package main import "fmt" func main() { var f int fmt.Scanln(&f) //your code goes here switch { case f<0: fmt.Println("Wrong Input") case f<20: fmt.Println("Infrasound") case f>20000: fmt.Println("Ultrasound") default: fmt.Println("Audible") } }
8th Apr 2023, 12:26 AM
Yasin Rahnaward
Yasin Rahnaward - avatar
0
if f = -34 the first case return true >>>Infrasound so you should include f >0 so the code will output Wrong Input when f < 0
7th Apr 2023, 9:28 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
0
switch { case f < 0: fmt.Println("Wrong Input") case f < 20: fmt.Println ("Infrasound") case f > 20000: fmt.Println ("Ultrasound") case f > 20 && f <= 20000: fmt.Println("Audible") }
8th Apr 2023, 4:00 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar