I am swift beginner. In this project I need to store user's input into dictionary. Then I use the data to do some calculation. I have a "calculate" button, when pressed, the program begins to calculate results and passes the result to the other screen. I am stuck here just can't get the data passed . Maybe there is something wrong with my "calculation" code. Please help.
import UIKit
class ViewController: UIViewController {
var student: [String: Int] = [:]
var g : String = ""
var gr : String = ""
var mean : Double = 0.0
@IBOutlet weak var t2: UITextField!
@IBOutlet weak var s1: UILabel!
@IBAction func add(_ sender: UIButton) {
let getInput1 = t1.text!
let getInput2 = Int(t2.text!)
if getInput1 != nil && getInput2! >= 0
{
student[getInput1] = getInput2
s1.text = getInput1
t1.text = nil
t2.text = nil
}else{
s1.text = "None"
}
}
@IBAction func calc(_ sender: Any) {
for (key, value) in student{
theSum = theSum + value
if count == 0
{
maxName = key
min = value
}
count = count + 1
}
mean = Double(theSum)/Double(student.count)
let grade1 = min
switch grade1
{
case 93...100: g = "A"
case 0...59: g = "F"
default: g = ""
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
}