GOLANG - 17 Code Project - Say The Numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

GOLANG - 17 Code Project - Say The Numbers

I try to do the project but i dont know why is wrong with my code. Could someone help me please? /* 17 Code Project - Say The Numbers You are making a robot that can speak numbers. Your robot should take 3 numbers in the range of 0-10 as input and output the corresponding texts in English.*/ package main import ( "fmt" "math/rand" "time" ) func main() { //your code goes here rand.Seed(time.Now().UnixNano()) for i:= 1; i <= 3; i++ { min := 0 max := 10 x := rand.Intn(max - min + 1) + min switch x { case 0: fmt.Println("Zero") case 1: fmt.Println("One") case 2: fmt.Println("Two") case 3: fmt.Println("Three") case 4: fmt.Println("Four") case 5: fmt.Println("Five") case 6: fmt.Println("Six") case 7: fmt.Println("Seven") case 8: fmt.Println("Eight") case 9: fmt.Println("Nine") case 10: fmt.Println("Ten") } } }

27th Jan 2022, 4:27 PM
Luis Jimenez
Luis Jimenez - avatar
4 Answers
+ 6
package main import "fmt" func main() { var input int for i:=0; i<3; i++ { fmt.Scanln(&input) switch input { case 0: fmt.Println("Zero") case 1: fmt.Println("One") case 2: fmt.Println("Two") case 3: fmt.Println("Three") case 4: fmt.Println("Four") case 5: fmt.Println("Five") case 6: fmt.Println("Six") case 7: fmt.Println("Seven") case 8: fmt.Println("Eight") case 9: fmt.Println("Nine") case 10: fmt.Println("Ten") } } } // Good Luck
28th Jan 2022, 12:20 AM
SoloProg
SoloProg - avatar
+ 1
You have no input, and i expect the input will be strings, so i coded for instance case "4": and not case 4:
27th Jan 2022, 4:59 PM
Paul
Paul - avatar
0
Is there an error here I'm not seeing. When I run it I get 1 2 3 as input without any opportunity to enter data. TIA package main import "fmt" func main() { //your code goes here var a int for x := 1; x <= 3; x++ { fmt.Scanln(&a) switch a{ case 0: fmt.Println("Zero") case 1: fmt.Println("One") case 2: fmt.Println("Two") case 3: fmt.Println("Three") case 4: fmt.Println("Four") case 5: fmt.Println("Five") case 6: fmt.Println("Six") case 7: fmt.Println("Seven") case 8: fmt.Println("Eight") case 9: fmt.Println("Nine") case 10: fmt.Println("Ten") } } }
17th Aug 2022, 5:54 PM
Ken Byrne
Ken Byrne - avatar
0
package main import "fmt" func main() { var input int for i:=0; i<3; i++ { fmt.Scanln(&input) switch input { case 0: fmt.Println("Zero") case 1: fmt.Println("One") case 2: fmt.Println("Two") case 3: fmt.Println("Three") case 4: fmt.Println("Four") case 5: fmt.Println("Five") case 6: fmt.Println("Six") case 7: fmt.Println("Seven") case 8: fmt.Println("Eight") case 9: fmt.Println("Nine") case 10: fmt.Println("Ten") } } } // done
18th Sep 2022, 4:28 AM
Kanisak Shakya
Kanisak Shakya - avatar