forked from 0x-r4bbit/intro-to-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
forked from 0x-r4bbit/intro-to-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Comments
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
} |
next issue #10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/prophen/intro-to-rust/blob/nikema's-notes/exercises/09.md
The text was updated successfully, but these errors were encountered: