Im trying to calculate percentage for the questions I have right and my percentage is always 0 or 100. Help me get the right percentage.
initialized
var percentage = 0
@IBAction func getScore(_ sender: UIButton) {
questionsTotal = myAnswerArray.count
print ("This is how many questions I have (questionsTotal)")
for oneAns in myAnswerArray {
if oneAns.message == "Your correct" {
questionsRight = questionsRight + 1
}
}
print("This is how many questions I have right (questionsRight)")
percentage = questionsRight/questionsTotal * 100
print(percentage)
percentageString = String(percentage)
self.percentageStringUsed = percentageString + "%"
performSegue(withIdentifier: "passRes", sender: self)
}
please help me.