Using a while loop to keep looping until condition is met.
When pin correct: Displays no message, exits program.
When user inputs wrong pin: Displays correct error message Pin is incorrect, Keeps promting user for input and keeps displaying Pin is incorrect.
When user inputs a non integer data type: Displays correct error message Pin is incorrect, Keeps promting user for input and keeps displaying Pin is incorrect.
Here is my code
fun main() {
println("Create PIN: ")
val pin = readln().toIntOrNull()
println("Enter PIN: ")
val input = readln().toIntOrNull()
while (input != pin) {
if (input == pin) {
println("PIN is correct")
}
else{
println("Pin is incorrect")
readln().toIntOrNull()
}
}
}
EDIT: I needed to walk away, was feeling like smashing my head against my keyboard haha. Ended up getting it working.
Here's the fix
fun main() {
println("Create PIN: ")
val pin = readln().toIntOrNull()
println("Enter PIN: ")
var input = readln().toIntOrNull()
while (input != pin)
{
println("PIN is incorrect")
input = readln().toIntOrNull()
}
if (input == pin){
println("PIN is correct")
}
}