Guest User

Untitled

a guest
Sep 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ResultViewController: UIViewController {
  4. @IBOutlet weak var correctPercentLabel: UILabel! //正解率ラベル
  5.  
  6. override func viewDidLoad() {
  7. super.viewDidLoad()
  8.  
  9. //問題数を取得する
  10. let questionCount = QuestionDataManager.sharedInstance.questionDataArray.count
  11.  
  12. //正解数を取得する
  13. var correctCount: Int = 0
  14.  
  15. //正解数を計算する
  16. for questionData in QuestionDataManager.sharedInstance.questionDataArray {
  17. if questionData.isCorrect() {
  18. //正解数を増やす
  19. correctCount += 1
  20.  
  21. }
  22. }
  23.  
  24. //正解率の計算
  25. let correctPercent: Float = (Float(correctCount) / Float(questionCount)) * 100
  26.  
  27. //正解数率を少数第一位まで計算して画面に反映する
  28. correctPercentLabel.text = String(format: "%.1f", correctPercent) + "%"
  29. }
  30.  
  31. override func didReceiveMemoryWarning() {
  32. super.didReceiveMemoryWarning()
  33. // Dispose of any resources that can be recreated.
  34. }
  35.  
  36.  
  37. }
Add Comment
Please, Sign In to add comment