0

I cannot solve the problem of the Sound Frequencies course.

That is the task: ---------------------------------- The human ear can hear sounds with frequencies in the range of 20 Hz to 20,000 Hz. This is called the Audible frequency. Anything below 20 Hz is called Infrasound, while anything above 20,000 Hz is called Ultrasound. You need to make a program that takes a sound frequency as input and outputs the corresponding category. Sample Input: 1800 Sample Output: Audible In case thegiven input is negative, your program should output "Wrong Input". ---------------------------------- This is my solution so far: ---------------------------------- package main import "fmt" func main() { var f int fmt.Scanln(&f) switch { case f>20 && f<20000: fmt.Println("Audible") case f >20000: fmt.Println("Ultrasound") case f <20: fmt.Println("Infrasound") case f <0: fmt.Println("Wrong Input") } } ---------------------------------- All test cases are correct except for test case 6 Where is the mistake ?

15th Nov 2021, 1:54 PM
Rusty
5 Antworten
+ 1
Rusty -1 < 20 would be also true -1 < 0 would be also true Change your 3rd case. check description again and apply condition
15th Nov 2021, 2:09 PM
A͢J
A͢J - avatar
+ 3
switch { case f>=20 && f<=20000: fmt.Print("Audible") case f>20000: fmt.Print("Ultrasound") case f<20 && f>=0: fmt.Print("Infrasound") default: fmt.Print("Wrong Input") }
15th Nov 2021, 3:07 PM
SoloProg
SoloProg - avatar
+ 2
Thanks, didn't know that there was default
15th Nov 2021, 6:07 PM
Rusty
+ 2
package main import "fmt" func main() { var f int fmt.Scanln(&f) if f >= 20 && f <= 20000 { fmt.Println("Audible") }else if f > 20000 { fmt.Println("Ultrasound") }else if f >= 0 && f < 20 { fmt.Println("Infrasound") }else { fmt.Println("Wrong Input") } //your code goes here }
28th Sep 2022, 9:07 AM
Ridho Reynaldo
Ridho Reynaldo - avatar
0
package main import "fmt" func main() { var frequencies int fmt.Scanln(&frequencies) switch { case frequencies < 0: fmt.Println("Wrong Input") case frequencies < 20: fmt.Println("Infrasound") case frequencies > 20000: fmt.Println("Ultrasound") default: fmt.Println("Audible") } }
29th Oct 2022, 12:45 AM
Joel Bello Lara
Joel Bello Lara - avatar