-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got everything working, except the following block match input_name.cmp(&String) { Ordering::Equal => let input_name = "Jakob", } Translating from Python if inputName == "": inputName = "Jakob"
- Loading branch information
1 parent
45cd9c3
commit 71d5c79
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/second-edition/ch02-00-guessing-game-tutorial.html | ||
// Because rust asked so nicely, I decided to rename my variables | ||
// https://doc.rust-lang.org/book/ch03-02-data-types.html | ||
// https://stackoverflow.com/questions/27043268/convert-a-string-to-int | ||
|
||
use std::io; | ||
use std::cmp::Ordering; | ||
|
||
fn main() { | ||
|
||
println!("What's your name? "); | ||
|
||
let mut input_name = String::new(); | ||
|
||
io::stdin().read_line(&mut input_name) | ||
.expect("Failed to read line"); | ||
|
||
//match input_name.cmp(&String) { | ||
// Ordering::Equal => let input_name = "Jakob", | ||
//} | ||
|
||
println!("Type in a number, {}", input_name); | ||
|
||
let mut input_var1 = String::new(); | ||
|
||
io::stdin().read_line(&mut input_var1) | ||
.expect("Failed to read line"); | ||
|
||
let input_var1: u32 = input_var1.trim().parse() | ||
.expect("Please type a number."); | ||
|
||
println!("Type in another number, {}", input_name); | ||
|
||
let mut input_var2 = String::new(); | ||
|
||
io::stdin().read_line(&mut input_var2) | ||
.expect("Failed to read line"); | ||
|
||
let input_var2: u32 = input_var2.trim().parse() | ||
.expect("Please type a number."); | ||
|
||
println!("Now add {} and {}", input_var1, input_var2); | ||
|
||
let mut input_sum = String::new(); | ||
|
||
io::stdin().read_line(&mut input_sum) | ||
.expect("Failed to read line"); | ||
|
||
let input_sum: u32 = input_sum.trim().parse() | ||
.expect("Please type a number."); | ||
|
||
let answer = &input_var1 + &input_var2; | ||
|
||
match input_sum.cmp(&answer) { | ||
Ordering::Less => println!("Value too low {}", input_name), | ||
Ordering::Greater => println!("Value too high {}", input_name), | ||
Ordering::Equal => println!("Well done {}", input_name), | ||
} | ||
} |