Hello!
I am having a problem with my program.I have to write a program that uses repitition and
switch statements to print the song "The Twelve Days of Christmas." One switch statement
should be used to print the days (i.e "First","Second" etc). A separate switch statement
should be used to print the remainder of each verse.
But the program I have written do not fulfill the above conditions. I don't know how to
use the two switch statements that alternate after one another. I am in a need of help.
Can any one help? I'll be thankful.
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=24;i++)
for(j=1;j<=24;j++)
{
if(i%2==1)
switch(i)
{
case 1:
cout<<"On the first day of Christmas\nmy true love sent to me:"<<endl;
break;
case 3:
cout<<"On the second day of Christmas\nmy true love sent to me:"<<endl;
break;
case 5:
cout<<"On the third day of Christmas\nmy true love sent to me:"<<endl;
break;
case 7:
cout<<"On the fourth day of Christmas\nmy true love sent to me:"<<endl;
break;
case 9:
cout<<"On the fifth day of Christmas\nmy true love sent to me:"<<endl;
break;
case 11:
cout<<"On the sixth day of Christmas\nmy true love sent to me:"<<endl;
break;
case 13:
cout<<"On the seventh day of Christmas\nmy true love sent to me:"<<endl;
break;
case 15:
cout<<"On the eighth day of Christmas\nmy true love sent to me:"<<endl;
break;
case 17:
cout<<"On the ninth day of Christmas\nmy true love sent to me:"<<endl;
break;
case 19:
cout<<"On the tenth day of Christmas\nmy true love sent to me:"<<endl;
break;
case 21:
cout<<"On the eleventh day of Christmas\nmy true love sent to me:"<<endl;
break;
case 23:
cout<<"On the twelfth day of Christmas\nmy true love sent to me:"<<endl;
break;
default:
break;
}
}
if(j%2==0)
{
switch(j)
{
case 2:
cout<<"A Partridge in a Pear Tree"<<endl;
break;
case 4:
cout<<"Two Turtle Doves and\na Partridge in a Pear Tree"<<endl;
break;
case 6:
cout<<"Three French Hens\nTwo Turtle Doves and\na Partridge in a Pear Tree"<<endl;
break;
case 8:
cout<<"Four Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 10:
cout<<"Five Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 12:
cout<<"Six Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 14:
cout<<"Seven Swans a Swimming\nSix Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 16:
cout<<"Eight Maids a Milking\nSeven Swans a Swimming\nSix Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 18:
cout<<"Nine Ladies Dancing\nEight Maids a Milking\nSeven Swans a Swimming\nSix Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 20:
cout<<"Ten Lords a Leaping\nNine Ladies Dancing\nEight Maids a Milking\nSeven Swans a Swimming\nSix Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 22:
cout<<"Eleven Pipers Piping\nTen Lords a Leaping\nNine Ladies Dancing\nEight Maids a Milking\nSeven Swans a Swimming\nSix Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
case 24:
cout<<"12 Drummers Drumming\nEleven Pipers Piping\nTen Lords a Leaping\nNine Ladies Dancing\nEight Maids a Milking\nSeven Swans a Swimming\nSix Geese a Laying\nFive Golden Rings\nFour Calling Birds\nThree French Hens\nTwo Turtle Doves\nand a Partridge in a Pear Tree"<<endl;
break;
default:
break;
}
}
getch();
}