Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::str::{FromStr};
- fn main() {
- let weight = input::<i64>("Patient's weight (kg):");
- let time_passed = input::<i64>("How much time has passed from the previous dose (full hours): ");
- let total_dose = input::<i64>("The total dose for the last 24 hours (mg): ");
- if total_dose >= 4000{
- println!("You can't take another dose this day")
- } else {
- let next_dose = calculate_dose( weight, time_passed, total_dose);
- println!("The amount of Parasetamol to give to the patient: {}", next_dose)
- }
- }
- fn calculate_dose(weight: i64, time_passed: i64, total_dose: i64) -> i64{
- if time_passed < 6 {
- 0
- } else {
- let next_dose = weight * 15;
- if next_dose + total_dose > 4000 {
- 4000 - total_dose
- } else {
- next_dose
- }
- }
- }
- fn input<F>(prompt: &str) -> F where
- F: FromStr {
- use std::io::{stdin, self, Write};
- print!("{}", prompt);
- io::stdout().flush().unwrap();
- let mut guess = String::new();
- let _= stdin().read_line(&mut guess);
- let a = guess.to_string().trim().parse::<F>();
- match a {
- Ok(v) => v,
- Err(_) => panic!("Parse failed!")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement