Write a script called old Macdonald that prints the lyrics to the nursery rhyme
ID: 3870535 • Letter: W
Question
Write a script called old Macdonald that prints the lyrics to the nursery rhyme "Old MacDonald Had a Farm". The program should input the type of animal and the sound it makes. For example, if the input is animal= 'cow, and sound = 'moo' , the following will be printed. Old MacDonald had a farm, E-I-E-I-O! And on that farm he had a cow, E-I-E-I-O! With a moo-moo here, and moo-moo there. Here a moo, there a moo, everywhere a moo-moo. old MacDonald had a farm, E-I-E-I-o! Use the fprintffunction to print the lines of the lyrics. As an example, if fprintf is to print sound 4 times, the locations of the word assigned to the variable sound will need to use four %s to preserve the space where you want the value of the variable sound to be placed in the line of text. You also need to have the variable name sound listed 4 times after the sentence For example, if I wanted to print the names of my 3 sons, I would use fprintf ('The names of my 3 sons are %s, %s, and %s. ", son, son2,son3) where son1-Sam, son2-Jim, and so n3c,Dan, No comments, no checking of input required for this problem Submit your m fileExplanation / Answer
anumal = "cow";
sound = "moo";
ending = "E-I-E-I-O";
fprintf("Old MacDonald had a farm, %s ", ending);
fprintf("And on that farm he had a %s, %s ", animal, ending);
fprintf("With a %s-%s here, and a %s-%s there ",sound, sound);
fprintf("Here is a %s, there is a %s, everywhere a %s-%s ", sound, sound, sound, sound);
fprintf("Old MacDonald had a farm, %s ", ending);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.