-
-
Save Najaf/67953d09f477b78995adaa919b6e284d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::io::Write; | |
use std::str::FromStr; | |
fn prompt<F>(question: &str) -> Result<F, F::Err> | |
where F: FromStr | |
{ | |
let mut answer = String::new(); | |
print!("{} ", question); | |
let _ = io::stdout().flush(); | |
let _ = io::stdin().read_line(&mut answer); | |
answer.trim().to_string().parse::<F>() | |
} | |
fn main() { | |
let width: u32 = prompt("Width in feet").unwrap(); | |
let length: u32 = prompt("Length in feet").unwrap(); | |
let area = width * length; | |
let square_feet_per_gallon = 350; | |
let gallons; | |
if 0 == area % square_feet_per_gallon { | |
gallons = area / square_feet_per_gallon; | |
} else { | |
gallons = (area / square_feet_per_gallon) + 1; | |
} | |
println!("You will need to purchase {} gallons to cover {} square feet", | |
gallons, | |
area); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment