15 lines
416 B
Rust
15 lines
416 B
Rust
use std::io::{BufRead, BufReader};
|
|
use std::fs::File;
|
|
|
|
fn main (){
|
|
let filename = "./input_example.txt";
|
|
let file = BufReader::new(File::open(filename).expect("Unable to open file"));
|
|
let mut calories = 0;
|
|
|
|
for line in file.lines() {
|
|
let snack_calories : i32 = line.trim().parse().unwrap();
|
|
calories += snack_calories;
|
|
}
|
|
|
|
println!("Total lines are: {}", calories);
|
|
}
|