Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "strings"
- )
- func main() {
- // Set a flag to determine if the user is cheating
- isCheating := false
- // Define a function to check if the user is cheating
- checkForCheats := func(input string) {
- // Set a list of cheats
- cheats := []string{"cheat1", "cheat2", "cheat3"}
- // Iterate through the list of cheats
- for _, cheat := range cheats {
- // If the input contains a cheat, set the flag to true and break out of the loop
- if strings.Contains(input, cheat) {
- isCheating = true
- break
- }
- }
- }
- // Prompt the user for input
- fmt.Print("Enter a command: ")
- scanner := bufio.NewScanner(os.Stdin)
- if scanner.Scan() {
- userInput := scanner.Text()
- // Check if the user is cheating
- checkForCheats(userInput)
- // If the user is cheating, display a message and exit the program
- if isCheating {
- fmt.Println("Cheating is not allowed!")
- os.Exit(0)
- }
- // If the user is not cheating, continue with the program
- fmt.Println("Valid input")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement