Created
November 20, 2021 12:52
-
-
Save zgunz42/67c53f23051ef31ffaf821db68f35b5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func getUserInput(input interface{}) (int, error) { | |
var err error | |
switch t := input.(type) { | |
case *int: | |
_, err = fmt.Scanf("%d", input) | |
case *string: | |
_, err = fmt.Scanf("%s", input) | |
default: | |
fmt.Printf("unexpected type %T", t) | |
} | |
if(err != nil) { | |
return 0, err | |
} | |
return 0, nil | |
} | |
func getNumText(input int) { | |
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") | |
} | |
} | |
func main() { | |
//your code goes here | |
var num1, num2, num3 int | |
getUserInput(&num1) | |
getUserInput(&num2) | |
getUserInput(&num3) | |
getNumText(num1) | |
getNumText(num2) | |
getNumText(num3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment