//
// ViewController.swift
// chengji
//
// Created by ios0105 on 15/11/26.
// Copyright © 2015年 ios0105. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
//获取用户输入
@IBOutlet weak var chengji: UITextField!
//显示计算后的结果
@IBOutlet weak var jieguo: UILabel!
//点击计算分值
@IBAction func jisuan(sender: AnyObject) {
//将用户输入的文本转换为float
let score=(chengji.text! as NSString).floatValue
//进行比较
if(score>=90&&score<=100)
{
jieguo.text="优秀"
}
else if(score>=80&&score<90)
{
jieguo.text="良好"
}
else if(score>=70&&score<80)
{
jieguo.text="中等"
}
else if(score>=60&&score<70)
{
jieguo.text="及格"
}
else if(score<60)
{
jieguo.text="不及格"
}
else
{
jieguo.text="格式错误!请输入0-100之间的数字"
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
转载于:https://my.oschina.net/u/2509105/blog/542068