Created
August 17, 2018 05:07
-
-
Save v-stickykeys/e777be437edbe5f38a86c51c305702cd to your computer and use it in GitHub Desktop.
Order pizza for your SF meetup! aka my first Rust program
This file contains hidden or 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; | |
fn main() { | |
println!("How many RSVPS do you have for your Meetup?"); | |
let mut input = String::new(); | |
io::stdin().read_line(&mut input) | |
.expect("Failed to read input."); | |
let trimmed = input.trim(); | |
let rsvps = trimmed.parse::<u32>().expect("Must input an integer."); | |
let num_pies = calc_num_pies(rsvps); | |
println!("Order {} x-large pies from SOMA Pizza!", num_pies); | |
} | |
// Formula graciously provided by Rob Durst | |
fn calc_num_pies(rsvps: u32) -> u32 { | |
let x_large_factor = 0.8; | |
let num_attendees = (rsvps as f32) * 0.33; | |
let num_slices = num_attendees * 2.0; | |
let num_pies = ((num_slices / 8.0) * x_large_factor).round() as u32; | |
if num_pies < 1 { | |
return 1; | |
}; | |
return num_pies; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment