Skip to content

Instantly share code, notes, and snippets.

@Najaf
Created June 4, 2016 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Najaf/873ee221569a82e069bceae1cdd319d3 to your computer and use it in GitHub Desktop.
Save Najaf/873ee221569a82e069bceae1cdd319d3 to your computer and use it in GitHub Desktop.
use std::io;
use std::io::Write;
fn prompt(question: &str) -> String {
let mut answer = String::new();
print!("{}: ", question);
let _ = io::stdout().flush();
let _ = io::stdin().read_line(&mut answer);
answer.trim().to_string()
}
fn main() {
let (first, second) = (prompt("First number").parse::<i32>().unwrap(),
prompt("Second number").parse::<i32>().unwrap());
println!("{} + {} = {}", first, second, first + second);
println!("{} - {} = {}", first, second, first - second);
println!("{} * {} = {}", first, second, first * second);
println!("{} / {} = {}", first, second, first / second);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment