Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me on my yes and no loop I wanted a do-while instead but it\'s not w

ID: 3882010 • Letter: P

Question

Please help me on my yes and no loop I wanted a do-while instead but it's not working using xcode for swift

import Foundation

print("********************")

print("*THE PRICE IS RIGHT*")

print("******************** ")

var option: Int = 0

var answer = "y"

while answer != "y" || answer != "Y"{

repeat{

  

print("OPTION: ")

print(" [1] Easy -or- [2] Hard")

let option = Int(readLine()!)!

  

if option == 1{

print("EASY LEVEL")

print("Gusse a number between 1 and 50")

  

  

  

break;

  

}//LEVEL ONE

else if option == 2{

print("Gusse a number between 1 and 100")

print("HARD LEVEL")

  

break;

  

}//LEVE TWO

else{

print("INVAID NUMBER")

break;

}

}while option != 1 || option != 2

print("Play Again: yes [y] or n [n]")

_ = readLine()

}

Explanation / Answer

Remove the repeat keyword from the program as repeat-while is same as do-while. So for every repeat keyword there must be while loop.

Or

you can remove the while loop i.e. while answer!="y"||answer!='Y'

and place it here like this

................

}//LEVE TWO

else{

print("INVAID NUMBER")

break;

} while answer!="y"||answer!='Y'

}

while option != 1 || option != 2

print("Play Again: yes [y] or n [n]") and so on......

Then your program will be good to go.

I tried my best to help you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote