Pure Programmer
Blue Matrix


Cluster Map

Project: 99 Bottles of Beer Lyrics

Compute the full lyrics to the song 99 Bottles of Beer. Write a function to print a verse given the verse number. Be sure to handle the special cases when there are just one bottle of beer and no bottles of beer.

See [[99 Bottles of Beer]]

Output
$ rustc BottlesOfBeerLyrics.rs warning: unnecessary parentheses around assigned value --> BottlesOfBeerLyrics.rs:16:24 | 16 | numMinusOneBottles += (if num == 2 { " bottle" } else { " bottles" }); | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 16 - numMinusOneBottles += (if num == 2 { " bottle" } else { " bottles" }); 16 + numMinusOneBottles += if num == 2 { " bottle" } else { " bottles" }; | error[E0368]: binary assignment operation `+=` cannot be applied to type `&str` --> BottlesOfBeerLyrics.rs:11:3 | 11 | numBottles += "s"; | ----------^^^^^^^ | | | cannot use `+=` on type `&str` error[E0277]: cannot subtract `String` from `isize` --> BottlesOfBeerLyrics.rs:15:55 | 15 | numMinusOneBottles = if num == 1 { "No" } else { num - 1.to_string() }; | ^ no implementation for `isize - String` | = help: the trait `Sub<String>` is not implemented for `isize` = help: the following other types implement trait `Sub<Rhs>`: <&'a isize as Sub<isize>> <&isize as Sub<&isize>> <isize as Sub<&isize>> <isize as Sub> error[E0368]: binary assignment operation `+=` cannot be applied to type `&str` --> BottlesOfBeerLyrics.rs:16:2 | 16 | numMinusOneBottles += (if num == 2 { " bottle" } else { " bottles" }); | ------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | cannot use `+=` on type `&str` error: aborting due to 3 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0368. For more information about an error, try `rustc --explain E0277`.

Solution