Project: Old MacDonald Lyrics
Compute the full lyrics to the song Old MacDonald Had a Farm. Write a function to print a verse given the verse number. Use an array to hold the animal names and another array to hold the sounds that they make.
See [[Old MacDonald Had a Farm]]
Output
$ rustc OldMacDonaldLyrics.rs
error[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:14:63
|
14 | println!("and on that farm he had a {}, E-I-E-I-O,", animals[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:15:32
|
15 | print!("with a {} {}", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:15:45
|
15 | print!("with a {} {}", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:16:46
|
16 | println!(" here and a {} {} there,", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:16:59
|
16 | println!(" here and a {} {} there,", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:17:44
|
17 | println!("here a {}, there a {},", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:17:57
|
17 | println!("here a {}, there a {},", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:18:40
|
18 | println!("everywhere a {} {}", sounds[num], sounds[num]);
| ^^^ 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[E0277]: the type `[&'static str]` cannot be indexed by `isize`
--> OldMacDonaldLyrics.rs:18:53
|
18 | println!("everywhere a {} {}", sounds[num], sounds[num]);
| ^^^ 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[E0308]: mismatched types
--> OldMacDonaldLyrics.rs:26:13
|
26 | while i < animals.len() {
| - ^^^^^^^^^^^^^ expected `isize`, found `usize`
| |
| expected because this is `isize`
|
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
|
26 | while i < animals.len().try_into().unwrap() {
| ++++++++++++++++++++
error: aborting due to 10 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.