You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
610 B
Go

1 year ago
package main
import (
"fmt"
"os"
"strconv"
)
const exitCommand = "/q"
func main() {
var userInput string
fmt.Printf("Welcome to trunc.go. Please enter %s to exit the program.\n", exitCommand)
for {
fmt.Println("Enter a float number:")
fmt.Scan(&userInput)
if userInput == exitCommand {
fmt.Println("Closing...")
os.Exit(0)
}
userFloat, err := strconv.ParseFloat(userInput, 64)
if err != nil {
fmt.Println("Opps you entered and incorrect input! Try again.")
continue
}
fmt.Printf("You entered: %f, the interger component of that is: %d\n", userFloat, int(userFloat))
}
}