This commit is contained in:
2024-03-05 18:08:32 +01:00
commit 364198aab5
4 changed files with 42 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "kalkulatorPredkosci"
version = "0.1.0"

8
Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "kalkulatorPredkosci"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

26
src/main.rs Normal file
View File

@@ -0,0 +1,26 @@
use std::{io, str::ParseBoolError};
fn main() {
let mut droga = String::new();
let mut czas = String::new();
//wyswielt i pobierz droge
println!("Podaj droge przejechana przez samochod w kilometrach\n");
io::stdin().read_line(&mut droga).expect("Wrong input");
//wyswietl i pobierz czas
println!("Podaj czas przebyty przez samochod w minutach\n");
io::stdin().read_line(&mut czas).expect("Wrong input");
let droga: f32 = droga.trim().parse().expect("Failed to convert string");
let czas: f32 = czas.trim().parse().expect("Failed to convert string");
let wynik = kalkualtorPredkosci(droga, czas);
println!("Predkosc samochodu wynosi: {}KM/h", wynik);
}
fn kalkualtorPredkosci(mut droga: f32, mut czas: f32) -> f32{
droga*=1000.0;
czas*=60.0;
let mut wynik:f32 = (droga / czas * 3.6) as f32;
return wynik.round();
}