GitHub

Practice

Practice - 023

A program to explain MATCH

use text_io::scan;
// Read an integer value between 1 to 5 and print it in words
fn main() {
practice23()
}
fn practice23() {
let num: i32;
println!("Enter the number:");
scan!("{}", num);
match num {
1 => println!("ONE"),
2 => println!("TWO"),
3 => println!("THREE"),
4 => println!("FOUR"),
5 => println!("FIVE"),
_ => (),
}
}

Config

[package]
name = "practice"
version = "0.1.0"
edition = "2021"
[dependencies]
text_io = "0.1.12"

Result

Enter the number:
2
TWO
Enter the number:
6
Previous
Practice - 022