/****************************************************************************** * This program computes NFL passer ratings. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] #[macro_use] mod utils; fn main() { match (|| -> Result<(), utils::CustomError>{ let mut input_str:String; let mut attempts:isize; input_str = Utils.prompt("Number of attempts: "); attempts = input_str.trim().parse::().unwrap()?; let mut completions:isize; input_str = Utils.prompt("Number of completions: "); completions = input_str.trim().parse::().unwrap()?; let mut touchdown_passes:isize; input_str = Utils.prompt("Number of touchdown passes: "); touchdown_passes = input_str.trim().parse::().unwrap()?; let mut interceptions:isize; input_str = Utils.prompt("Number of interceptions: "); interceptions = input_str.trim().parse::().unwrap()?; let mut passing_yards:isize; input_str = Utils.prompt("Number of passing yards: "); passing_yards = input_str.trim().parse::().unwrap()?; let mut which:isize; input_str = Utils.prompt("1 for NFL or 2 for NCAA: "); which = input_str.trim().parse::().unwrap()?; if which == 1 { let a:f64 = (f64::from(completions) / f64::from(attempts) - 0.3f64) * 5.f64; let b:f64 = (f64::from(passing_yards) / f64::from(attempts) - 3.f64) * 0.25f64; let c:f64 = f64::from(touchdown_passes) / f64::from(attempts) * 20.f64; let d:f64 = 2.375f64 - (f64::from(interceptions) / f64::from(attempts) * 25.f64); let rating:f64 = (a + b + c + d) / 6.f64 * 100.f64; println!("NFL Passer rating: {0:.1}", rating); } else { let a:f64 = 8.4f64 * (passing_yards) as f64; let b:f64 = 330.f64 * (touchdown_passes) as f64; let c:f64 = 100.f64 * (completions) as f64; let d:f64 = 200.f64 * (interceptions) as f64; let rating:f64 = (a + b + c - d) / (attempts) as f64; println!("NCAA Passer rating: {0:.1}", rating); } return Ok(()); })() { Ok(()) => {}, Err(ex) => { match ex { utils::CustomError::NumberFormatError(ex) => { println!("{}", String::from("Bad input! ") + &format!("{}", ex)); } _ => { println!("Don't know what went wrong!"); } } } }; }