use std::io::{self, Write};

fn main() 
{
    let mut values: Vec<f32> = Vec::new();

    for n in 0..4
    {
        let mut is_int: bool = false;
        while !is_int 
        {
            let mut input = String::new();
            print!("Please input quantity for quarter #{}: ", n + 1);
            let _ = io::stdout().flush();
            io::stdin().read_line(&mut input).expect("failed to read from stdin");
            match input.trim().parse::<f32>() 
            {
                Ok(i) => 
                {
                    values.push(i);
                    is_int = true;
                },
                Err(..) => 
                {
                    println!("Must be an integer!");
                    is_int = false;
                }
            }
        }
    }

    println!("The monthly average is: {:.1}", values.iter().sum::<f32>() / 12.0);
    println!("The quarterly average is: {:.1}", values.iter().sum::<f32>() / 4.0);
}