first commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
numero, tentativas := 7, 3
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
|
||||||
|
fmt.Println("Bem-vindo ao jogo de adivinhação!")
|
||||||
|
fmt.Printf("Você tem %d tentativas para adivinhar o número entre 1 e 10.\n", tentativas)
|
||||||
|
|
||||||
|
for i := 0; i <= tentativas; i++ {
|
||||||
|
if i == tentativas {
|
||||||
|
fmt.Println("Suas tentativas acabaram. O número correto era:", numero)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner.Scan()
|
||||||
|
chute := strings.TrimSpace(scanner.Text())
|
||||||
|
chuteInt, err := strconv.Atoi(chute)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Deve ser informado um número.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if chuteInt < 1 {
|
||||||
|
fmt.Println("O número deve ser maior que 0.")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if chuteInt < numero {
|
||||||
|
fmt.Println("O número é maior")
|
||||||
|
}
|
||||||
|
|
||||||
|
if chuteInt > numero {
|
||||||
|
fmt.Println("O número é menor")
|
||||||
|
}
|
||||||
|
|
||||||
|
if chuteInt == numero {
|
||||||
|
fmt.Println("Parabéns! Você acertou o número!")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user