vendredi 23 août 2019

I Want to return to question if user write other words than "Yes" "No" in my code with if/else

I Want to return to question if user write other words than "Yes" "No" in my code with if/else.

You only answer with "YES" or "NO" but answer like"sjfkhs" make me sad. if somebody write like "sdjk" i want to repeat the question.

fun main(args: Array<String>) {

    var CanI_Play: String
    var IfUrMotherDisturb: String
    var HaveYouFreeTime: String
var Question1 = "Can I play?"
    println(Question1)
    CanI_Play = readLine()!!.toUpperCase() //wstawienie !!. mówi komputerowi , że nie wprowadzimy null
    // czyli chyba pustego pola które w tym przypadku bedzie zmienione z małych liter na duże

    if (CanI_Play=="YES") {
    println("So you can play from now")
    }
    if (CanI_Play=="NO") {
        println("You can't play yet...:(")
        println("Have You free time?")
        HaveYouFreeTime = readLine()!!.toUpperCase()
        if (HaveYouFreeTime=="NO") {
            println("Do what You should do and You can play")
        }
        if (HaveYouFreeTime=="YES") {
            println("If Your mother disturb?")
            IfUrMotherDisturb = readLine()!!.toUpperCase()

            if (IfUrMotherDisturb=="YES"){
                println("Bad news. Time to look for new house. OMFG")
            }
            if (IfUrMotherDisturb=="NO"){
                println("Great news! You can play!")
            }
            else{
                println("I Want to return to question IfUrMotherDisturb")
            }







        }
        else{
            println("I want to return to question HaveYouFreeTime")
        }

    }
    else{
        println("I want to return to question CanI_Play")
    }


}

Aucun commentaire:

Enregistrer un commentaire