Unverified Commit f92cd774 authored by Aral Balkan's avatar Aral Balkan
Browse files

Update to separate lyric creation and display based on Ch.4 knowledge

parent a97dacc8
fn display_lyrics_for_day(day: u32) {
fn lyrics_for_day(day: u32) -> String {
let mut days_to_presents = vec![
("first", "And a partridge in a pear tree."),
("second", "Two turtle doves"),
......@@ -21,25 +21,31 @@ fn display_lyrics_for_day(day: u32) {
if day == 0 {
// Special case lyrics for first day.
present_for_day_in_english = "A partridge in a pear tree.";
present_for_day_in_english = "A partridge in a pear tree.\n";
} else {
present_for_day_in_english = details.1;
}
println!("\nOn the {} day of Christmas, my true love sent to me\n{}", day_in_english, present_for_day_in_english);
let mut lyrics = String::from(format!("\nOn the {} day of Christmas, my true love sent to me\n{}", day_in_english, present_for_day_in_english));
days_to_presents.reverse();
for (index, details) in days_to_presents.iter().enumerate() {
if index > days_to_presents.len() - day as usize - 1 {
println!("{}", details.1);
lyrics.push_str(&format!("{}\n", details.1));
}
}
lyrics
}
fn main() {
// Display the lyrics for the twelve days.
// Compose the lyrics.
let mut lyrics = String::new();
for day in 0..12 {
display_lyrics_for_day(day);
lyrics.push_str(&lyrics_for_day(day));
}
// Display the lyrics.
println!("{}", lyrics);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment