Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9. Introducing loops #9

Open
prophen opened this issue Jan 23, 2020 · 2 comments
Open

9. Introducing loops #9

prophen opened this issue Jan 23, 2020 · 2 comments

Comments

@prophen
Copy link
Owner

prophen commented Jan 23, 2020

https://github.com/prophen/intro-to-rust/blob/nikema's-notes/exercises/09.md

@prophen
Copy link
Owner Author

prophen commented Jan 23, 2020

use std::io;
use std::process;

fn main() {
    loop {
        println!("Please enter the first number: ");
        let mut first = String::new();
        io::stdin().read_line(&mut first).unwrap();
        let a: u32;
        match first.trim().parse() {
            Ok(value) => a = value,
            Err(_error)=> {
                eprintln!("This is unfortunately not a number");
                process::exit(1)
            }
        };
    
        println!("Please enter the second number: ");
        let mut second = String::new();
        io::stdin().read_line(&mut second).unwrap();
        let b: u32;
        match second.trim().parse() {
            Ok(value) => b = value,
            Err(_error)=> {
                eprintln!("This is unfortunately not a number");
                process::exit(1)
            }
        };
    
        let result = sum(a, b);
        println!("Result: {}", result);
    }
}
fn sum(a: u32, b:u32 ) -> u32 {
    a + b
}

image

@prophen
Copy link
Owner Author

prophen commented Jan 23, 2020

next issue #10
Go back to wiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant