From 2d8f1bb1607b25e7173e4e3eee7ba4599420ee32 Mon Sep 17 00:00:00 2001 From: mikysett Date: Wed, 9 Nov 2022 15:29:00 +0000 Subject: [PATCH] feat(negative_spelling): create new exam exercise for rust --- subjects/negative_spelling/README.md | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 subjects/negative_spelling/README.md diff --git a/subjects/negative_spelling/README.md b/subjects/negative_spelling/README.md new file mode 100644 index 000000000..34fa64f35 --- /dev/null +++ b/subjects/negative_spelling/README.md @@ -0,0 +1,49 @@ +## negative_spelling + +### Instructions + +In this exercise, you'll create the function `neg_spell` that will spell a negative number. + +Here are some examples of what your function should return: + +- `-1` -> `"minus one"` +- `-14` -> `"minus fourteen"` +- `-348` -> `"minus three hundred forty-eight"` +- `-1002` -> `"minus one thousand two"` + +> Only negative numbers will be accepted, up to `"minus one million"`. +> If a positive number is passed the function should return `"error: positive number"`. + +### Expected function + +```rust +pub fn neg_spell(n: i64) -> String { + +} +``` + +### Usage + +Here is a program to test your function. + +```rust +use spelling::*; + +fn main() { + println!("{}", neg_spell(-1234)); + println!("{}", neg_spell(100)); +} +``` + +And its output: + +```console +$ cargo run +minus one thousand two hundred thirty-four +error: positive number +$ +``` + +### Notions + +- [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)