Console 1: moyenne
This commit is contained in:
parent
971684a85c
commit
8f8a8346e5
@ -1,3 +1,34 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user