Advertisement
Guest User

Untitled

a guest
Sep 14th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.82 KB | None | 0 0
  1. use std::io;
  2. use std::io::Write;
  3. use std::thread;
  4. use std::time::Duration;
  5.  
  6. fn main() {
  7.     let mut height = String::new();
  8.     let mut weight = String::new();
  9.  
  10.     println!("Kalkulator BMI, witamy!");
  11.     thread::sleep(Duration::from_secs(1));
  12.  
  13.     print!("Wpisz swój wzrost: ");
  14.     io::stdout().flush().unwrap(); // Make input in same line as print
  15.     io::stdin().read_line(&mut height).expect("Failed to read line");
  16.     let height: f32 = height.trim().parse().unwrap();
  17.  
  18.     print!("Wpisz teraz swoją wagę: ");
  19.     io::stdout().flush().unwrap(); // Make input in same line as print
  20.     io::stdin().read_line(&mut weight).expect("Failed to read line");
  21.     let weight: f32 = weight.trim().parse().unwrap();
  22.  
  23.     let bmi: f32 = weight / (height / 100.0).powf(2.0) as f32;
  24.     println!("Twoje BMI: {bmi:.1}");
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement