+ 1

Say the number prgram

Convert number to word Here is my code package main import "fmt" func switchfunc(o int){ switch o{ 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") default: fmt.Println("Zero") } } func main() { var i,m,n int fmt.Scanln(&i) fmt.Scanln(&m) fmt.Scanln(&n) switchfunc(i) switchfunc(m) switchfunc(n) } But it fails in some test cases

19th May 2021, 1:22 PM
Karan
Karan - avatar
8 Antworten
+ 7
package main import "fmt" func main() { //your code goes here for i := 1; i<=3; i++{ var i int fmt.Scanln(&i) switch i { 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") default: fmt.Println(i) } } }
7th Jun 2021, 5:50 PM
Vrushabh
Vrushabh - avatar
+ 6
Thanks, silly mistake Final Correct Code:- package main import "fmt" func switchfunc(o int){ switch o{ 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") default: fmt.Println("Zero") } } func main() { var i,m,n int fmt.Scanln(&i) fmt.Scanln(&m) fmt.Scanln(&n) switchfunc(i) switchfunc(m) switchfunc(n) }
20th May 2021, 9:50 AM
Karan
Karan - avatar
+ 4
Karan, what about 10, you don't check it.
19th May 2021, 1:46 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Say The Number package main import "fmt" func switchfunc(o int){ switch o{ 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") default: fmt.Println("Zero") } } func main() { var i,m,n int fmt.Scanln(&i) fmt.Scanln(&m) fmt.Scanln(&n) switchfunc(i) switchfunc(m) switchfunc(n) }
12th Sep 2021, 3:30 PM
Schawnnara Jiri Jeena-Myrr
Schawnnara Jiri Jeena-Myrr - avatar
+ 1
package main import ( "fmt" ) func main() { var x, y, z int fmt.Scanln(&x) fmt.Scanln(&y) fmt.Scanln(&z) dictionary := map[int]string{0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine", 10: "Ten", } fmt.Println(dictionary[x]) fmt.Println(dictionary[y]) fmt.Println(dictionary[z]) }
4th May 2022, 8:19 AM
Michael
Michael - avatar
0
package main import "fmt" func main() { robotNumbers := []string{ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", } var x, y, z int ScanTerminal(&x, &y, &z) TextOutput(robotNumbers, x, y, z) } func ScanTerminal(x *int, y *int, z *int) { fmt.Scanln(x) fmt.Scanln(y) fmt.Scanln(z) } func TextOutput(slice []string, num ...int) { if num == nil || len(num) < 3 { fmt.Println("Invalid value. Must have three numbers") } for _, v := range num { for n := range slice { if n == v { fmt.Println(slice[n]) } } } }
1st Jan 2022, 11:58 PM
max
max - avatar
0
package main import "fmt" func main() { //your code goes here var num1, num2, num3 int var first, second, third string fmt.Scanln(&num1) fmt.Scanln(&num2) fmt.Scanln(&num3) arr1 := [11]int{0,1,2,3,4,5,6,7,8,9,10} arr2 := [11]string{"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"} for i:= 0; i<=10 ; i++ { if (num1 == arr1[i]) { first = arr2[i] } if (num2 == arr1[i]) { second = arr2[i] } if (num3 == arr1[i]) { third = arr2[i] } } fmt.Println(first) fmt.Println(second) fmt.Println(third) }
8th Sep 2022, 10:55 PM
bhetuwal sagar
bhetuwal sagar - avatar
0
package main import "fmt" var validWrittenNumbers = map[int]string{ 0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine", 10: "Ten", } func printValidWrittenNumber(candidateNumber int) { if stringNumber, ok := validWrittenNumbers[candidateNumber]; ok { fmt.Println(stringNumber) } } func main() { inputTimes := 3 for index := 0; index < inputTimes; index++ { var candidateNumber int _, _ = fmt.Scanln(&candidateNumber) printValidWrittenNumber(candidateNumber) } }
25th Nov 2022, 1:25 PM
Ricky Hidayat
Ricky Hidayat - avatar