Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.swift
- // lab04
- //
- // Created by student on 24/10/2022.
- //
- import Foundation
- func isLeap() {
- guard let year = Int(readLine()!) else {
- fatalError("Not a number!")
- }
- if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
- print("Podany rok jest przestepny.")
- } else {
- print("Podany rok nie jest przestepny.")
- }
- }
- func century() {
- print("Podaj rok: ")
- guard let cent = Int(readLine()!) else {
- fatalError("Not a number!")
- }
- if (cent >= 2 && cent <= 3010) {
- if (cent % 100 != 0) {
- print("Jest wiek \(cent / 100 + 1)")
- } else {
- print("Jest wiek \(cent / 100)")
- }
- } else {
- print("Podano bledna liczbe!")
- }
- }
- func scholarship() {
- print("Podaj srednia: ")
- guard let avg = Float(readLine()!) else {
- fatalError("Not a number!")
- }
- switch (avg) {
- case 0..<3:
- print("0")
- case 3..<4:
- print("100")
- case 4..<4.51:
- print("150")
- case 4.51..<5.01:
- print("200")
- default:
- print("Podano bledna srednia.")
- }
- }
- func getFloat() -> Float {
- guard let x = Float(readLine()!) else {
- fatalError("Not a number!")
- }
- return x
- }
- func calc() {
- print("Podaj pierwsza liczbe: ")
- let a = getFloat()
- print("Podaj druga liczbe: ")
- let b = getFloat()
- print("1 - dodawnanie, 2 - odejmowanie, 3 - mnozenie, 4 - dzielenie.")
- let c = getFloat()
- var result: Float = 0
- switch (c) {
- case 1:
- result = a + b
- case 2:
- result = a - b
- case 3:
- result = a * b
- case 4:
- if (b != 0) {
- result = a / b
- } else {
- print("Podano 0.")
- }
- default:
- print("Nie podano poprawnego dzialania.")
- }
- print("Wynik: \(result)")
- }
- func zipCode() {
- print("Podaj kod pocztowy: ")
- guard let zc = readLine() else {
- fatalError("Not a string!")
- }
- guard let zcTwo = Int(zc.prefix(2)) else {
- fatalError("Not a number!")
- }
- print(zcTwo)
- switch (zcTwo) {
- case 20..<25:
- print("Kod nalezy do wojewodztwa lubelskiego.")
- default:
- print("Kod nie nalezy do wojewodztwa lubelskiego.")
- }
- }
- func isVowel() {
- print("Podaj litere: ")
- guard let letter = readLine() else {
- fatalError("Not a string!")
- }
- switch (letter) {
- case "a", "e", "i", "o", "u", "y":
- print("Jest to samogloska.")
- case "1", "2", "3", "4", "5", "6", "7", "8", "9":
- print("Jest to liczba.")
- default:
- print("Jest to spolgloska.")
- }
- }
- //isLeap()
- //century()
- //scholarship()
- //calc()
- //zipCode()
- isVowel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement