Okay, I give up.
I am making a Flash card game where the app will randomize two numbers, then the user would enter the answer. The app will then tell the user if he/she is correct. But I cannot seem to figure out how to get it to add two numbers and check if the user's correct or not.
Any help is greatly appreciated!
Here's the code:
I am making a Flash card game where the app will randomize two numbers, then the user would enter the answer. The app will then tell the user if he/she is correct. But I cannot seem to figure out how to get it to add two numbers and check if the user's correct or not.
Any help is greatly appreciated!
Here's the code:
Code Block import UIKit import AVFoundation import Foundation class YouSolveIt: UIViewController { @IBOutlet var topProblem: UILabel! @IBOutlet var botProblem: UILabel! @IBOutlet var youAnswer: UITextField! @IBOutlet var actualCard: UIImageView! let speakit = AVSpeechSynthesizer() var problem1 = Int(0) var problem2 = Int(0) var answer = 0 var ranA = 0 var ranB = 0 override func viewDidLoad() { super.viewDidLoad() // Load Flash Card image: actualCard.image = UIImage(named: "FlashCard") solveitproblem() } func solveitproblem() { let ranA = Int(arc4random_uniform(UInt32(9))) let ranB = Int(arc4random_uniform(UInt32(9))) topProblem.text = String(ranA) botProblem.text = String(ranB) youAnswer.text = String(answer) let speakProblem = AVSpeechUtterance(string: "What is \(topProblem.text! + ", plus ," + botProblem.text!)") speakit.speak(speakProblem) } @IBAction func btncheckAnswer(_ sender: Any) { if (ranA) + (ranB) == answer { correctAnswer() } else { wrongAnswer() } } func correctAnswer() { let right = [1,2,3,4,5] let randomIndex = Int(arc4random_uniform(UInt32(right.count))) switch(randomIndex) { case 1: let speakRight = AVSpeechUtterance(string: "That is correct") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 2: let speakRight = AVSpeechUtterance(string: "You're right!") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 3: let speakRight = AVSpeechUtterance(string: "Correct! Let's try.") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 4: let speakRight = AVSpeechUtterance(string: "You are right! Next Try.") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() case 5: let speakRight = AVSpeechUtterance(string: "Great answer!") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() default: let speakRight = AVSpeechUtterance(string: "Very good!") speakit.speak(speakRight) youAnswer.text = "" solveitproblem() } } func wrongAnswer() { let wrong = [1,2,3,4,5] let randomIndex = Int(arc4random_uniform(UInt32(wrong.count))) switch(randomIndex) { case 1: let speakRight = AVSpeechUtterance(string: "That is wrong") speakit.speak(speakRight) case 2: let speakRight = AVSpeechUtterance(string: "You're wrong, please try again.") speakit.speak(speakRight) case 3: let speakRight = AVSpeechUtterance(string: "No, that's not it. Please try again.") speakit.speak(speakRight) case 4: let speakRight = AVSpeechUtterance(string: "No") speakit.speak(speakRight) default: let speakRight = AVSpeechUtterance(string: "I'm sorry, no. Please try again.") speakit.speak(speakRight) } } }