Pure Programmer
Blue Matrix


Cluster Map

Project: Roman Numerals

Ancient Rome used a system of numbers much different that the Hindu-Arabic numerals we use today. Today Roman Numerals are only used on movie copyrights, Olymipic games and the Superbowl. Write a program that converts the numbers from 1-2500 to [[Roman Numerals]] and prints them. Write a function that specifically does the Roman Numeral conversion. It should take an integer and return a string. The following table specifies the Roman Numerals and their corresponding integer values.

SymbolValue
I1
IV4
V5
IX9
X10
XL40
L50
XC90
C100
CD400
D500
CM900
M1000

With the right algorithm, generating Roman Numerals with the subtractice notation illustrated above is as simple as the additive form.

Output
$ rustc RomanNumerals.rs error[E0308]: mismatched types --> RomanNumerals.rs:14:34 | 14 | let mut currentPosition:isize = values.len() - 1; | ----- ^^^^^^^^^^^^^^^^ expected `isize`, found `usize` | | | expected due to this | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 14 | let mut currentPosition:isize = (values.len() - 1).try_into().unwrap(); | + +++++++++++++++++++++ error[E0277]: the type `[isize]` cannot be indexed by `isize` --> RomanNumerals.rs:16:22 | 16 | if value >= values[currentPosition] { | ^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the type `[&'static str]` cannot be indexed by `isize` --> RomanNumerals.rs:17:26 | 17 | result += romanSymbol[currentPosition]; | ^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[&'static str]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<&'static str>` to implement `Index<isize>` error[E0368]: binary assignment operation `+=` cannot be applied to type `&str` --> RomanNumerals.rs:17:4 | 17 | result += romanSymbol[currentPosition]; | ------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | cannot use `+=` on type `&str` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> RomanNumerals.rs:18:20 | 18 | value -= values[currentPosition]; | ^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0308]: mismatched types --> RomanNumerals.rs:23:9 | 10 | fn convertToRomanNumerals(i:isize) -> String { | ------ expected `String` because of return type ... 23 | return result; | ^^^^^^- help: try using a conversion method: `.to_string()` | | | expected `String`, found `&str` error: aborting due to 6 previous errors Some errors have detailed explanations: E0277, E0308, E0368. For more information about an error, try `rustc --explain E0277`.

Solution