Purchase Solution

Repetition and Switch Structures

Not what you're looking for?

Ask Custom Question

Write a program that uses repetition and switch structures to print the song "The Twelve Days of Christmas." One switch should be used the print the day (i.e., "First", "Second", "Third", etc.). and another switch structure should print the remainder of each verse.

Purchase this Solution

Solution Summary

This solution provides guidelines on how to write a program using repetition and switch structures.

Solution Preview

This is the algorithm:

$i=1;
While ($i <= 12) {
Switch ($i) {
Case 1:
Do Statement 1
Case 2:
Do Statement 2
Case 3:
Do Statement 3
Case 4:
Do Statement 4
Case 5:
Do Statement 5
Case 6:
Do Statement 6
Case 7:
Do Statement 7
Case 8:
Do Statement 8
Case 9:
Do Statement 9
Case 10:
Do Statement 10
Case 11:
Do Statement 11
Case 12:
Do Statement 12
}
$i = $i + 1;
}

The following is written in PHP:

<?php
$i=1;
While ($i <= 12) {
Switch ($i) {
Case 1:
echo nl2br("On the first day of Christmas, n");
echo nl2br("my true love sent to me n");
echo nl2br("A partridge in a pear tree. nn");
break;
Case 2:
echo nl2br("On the second day of Christmas, n");
echo nl2br("my true love sent to me n");
echo nl2br("Two turtle doves, n");
echo nl2br("And a partridge in a pear tree. nn ");
break;
Case 3:
echo nl2br("On the third day of Christmas, n");
echo nl2br("my true love sent to me n");
echo nl2br("Three French hens, n ");
echo nl2br("Two turtle doves, n ");
echo nl2br("And a partridge in a pear tree. nn");
break;
Case 4:
echo nl2br("On the fourth day of Christmas,n");
echo nl2br("my true love sent to me n");
echo nl2br("Four calling birds, n");
echo ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.