-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImperativeMain.swift
37 lines (26 loc) · 962 Bytes
/
ImperativeMain.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
class ImperativeMain {
static func main() {
print("What is your name?")
let name = readLine()!
print("Hello, \(name)" + ", welcome to the game!")
var exec = true
while(exec) {
let number = arc4random_uniform(5) + 1
print("Dear \(name), please guess a number from 1 to 5:")
let guess = Int(readLine()!)!
if guess == number {
print("You guessed right, \(name)!")
} else {
print("You guessed wrong, \(name)! The number was \(number).")
}
print("Do you want to continue, \(name)?")
let answer = readLine()!
switch answer {
case "y": exec = true
case "n": exec = false
default: exec = true
}
}
}
}