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") } } }
4 ответов
0
Ok so the problem was that "Wrong Input" is not the same as "Wrong input" ... Kill me
+ 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")
}
}
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
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") }