Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.swift
- // Zad1.1
- import Foundation
- var suma, liczba: Int
- var srednia: Double
- suma=0
- for _ in 0..<3 {
- liczba = Int.random(in:1..<101)
- suma+=liczba
- print("Liczba to:", liczba)
- }
- print("Suma liczb to: ", suma)
- srednia = (Double)(suma)/3.00
- print("Srednia liczb to: ", srednia)
- ////////////////////////////////////////////////
- //
- // ContentView.swift
- // Zad1.2
- // ?????
- import SwiftUI
- struct ContentView: View {
- @State private var a1: String = ""
- @State private var a2: String = ""
- @State private var a3: String = ""
- @State var suma: Int = 0
- @State var srednia: Double = 0.0
- @State var pomoc: Bool = false
- var body: some View {
- VStack{
- Text("Podaj 3 liczby:")
- .padding()
- TextField("Podaj 1: ", text: $a1)
- TextField("Podaj 2: ", text: $a2)
- TextField("Podaj 3: ", text: $a3)
- Button(action:{
- pomoc = true
- self.suma = (Int)(a1)! + (Int)(a2)! + (Int)(a3)!
- self.srednia = (Double)(suma/3)
- }, label: {
- Text("Oblicz")})
- if(pomoc){Text("Suma liczb: \(suma), a srednia: \(srednia)")}
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement