-4

I just need to find a way to work with input to do simple maths with it. I've been trying this for a couple of days for the advent of code 2019 day 1

use std::fs::File;
use std::io::{BufRead, BufReader, Error};

fn main() -> Result<(), Error> {
    let path = "input.txt";

    let input = File::open(path)?;
    let buffered = BufReader::new(input);

    for line in buffered.lines() {
        line.parse::<i32>().unwrap();
        line / 2;
        println!("{:?}", line);
    }

    Ok(())
}
Endzeit
  • 4,810
  • 5
  • 29
  • 52
  • 3
    Please use your *favorite search engine*. This has been asked multiple times and has even discussed in the book: https://rust-lang-nursery.github.io/rust-cookbook/file/read-write.html – hellow Dec 11 '19 at 09:24

1 Answers1

0

If you want your code to compile.

use std::fs::File;
use std::io::{BufRead, BufReader, Error};

fn main() -> Result<(), Error> {
    let path = "input.txt";

    let input = File::open(path)?;
    let buffered = BufReader::new(input);

    for line in buffered.lines() {
        println!("{:?}", line.unwrap().parse::<i32>().unwrap() / 2);
    }

    Ok(())
}
createproblem
  • 1,542
  • 16
  • 30