hi guys,,
i've this homework that i have to submit tomorrow..
and unluckily I didn't know how to do it..

it says :
Write a program that outputs "Al Eid Song" words..
"The five days of Al Eid"
Use a switch statement to display the following output for the 5 days.

Recommended Answers

All 13 Replies

Give it a try and come back with questions (including compiler errors).

i tried this.. i know it's wrong coz the output screen didn't show as the teacher wants,,
but anyway.. can someone give me an idea how to out out it without asking the user to enter anything.. and to display it all at once??

#include <iostream>
#include <string>
using namespace std;
int main ()
{

    int day;

    cout<<"Please enter any number of your choice to desplay the Eid song.";
    cin>> day;



    switch(day)
    {
    case 1:
        {
        cout<<"A partridge in a peartree."<<endl<<endl;
    break;
        }

    case 2:
        {
        cout<<"On the second day of Al Eid my true love gave to me,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree."<<endl<<endl;
    break;
        }

    case 3:
        {
        cout<<"On the second day of Al Eid my true love gave to me,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;
        }

    case 4:
        {
        cout<<"On the third day of Al Eid my true love gave to me,"<<endl
            <<"Four calling birds,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;
        }

    case 5:
        {
        cout<<"On the third day of Al Eid my true love gave to me,"<<endl
            <<"Five golden rings,"<<endl
            <<"Four calling birds,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;  
    default:   
    break;

        }
    }


return 0;
}

Each switch case should handle only one of the days. You need a loop around the switch. This will remove the need to ask for input. For each iteration of the loop, the switch statement will handle a different day.

Give that a try and come back with questions.

i'm sorry i didn't understand what u said,,
i'm beginner ,,pardon me.. would u plz explain more with examples??

i'm sorry i didn't understand what u said,,
i'm beginner ,,pardon me.. would u plz explain more with examples??

You have 5 days to output. You are going to use a switch to handle each day. This is where the loop comes in. You can make a loop with 5 iterations with the switch inside using the number of the iteration of the loop as the switch condition.

for (int i = 0; i < 5; i++)

You can then put your switch inside of that loop using the variable i as the condition of your switch.

what do u mean by using a switch to handle each day??

do u mean that each day should have alone switch??

check this out.. that last thing i did.. but still i need the user to enter something.. or else i won't get the full song at once.. dunnu why?! :S

#include <iostream>
using namespace std;
int main ()
{

    int day = 0; day < 5; day++;

    cout<<"Please enter any number of your choice to desplay the Eid song.";
    cin>> day;

    do
    {
        day++;

    switch(day)
    {
    case 1:
        {
        cout<<"A partridge in a peartree."<<endl<<endl;
    break;
        }

    case 2:
        {
        cout<<"On the second day of Al Eid my true love gave to me,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree."<<endl<<endl;
    break;
        }

    case 3:
        {
        cout<<"On the third day of Al Eid my true love gave to me,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;
        }

    case 4:
        {
        cout<<"On the fourth day of Al Eid my true love gave to me,"<<endl
            <<"Four calling birds,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;
        }

    case 5:
        {
        cout<<"On the fifth day of Al Eid my true love gave to me,"<<endl
            <<"Five golden rings,"<<endl
            <<"Four calling birds,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;  
    default:   
    break;

        }
    }
}while (day<=5);


return 0;
}

Almost there.

You just need to set the day variable to 0 instead of asking for input. Also you only need to output one day in each switch *case* because the switch statement will be executed 5 times because of the loop.

OK :D

i didn't understand that i need to output one day in each switch statemet :S

BUT:
i declared day as 0 only and removed the cin as u told me

And it WORKED.. thanks to u :D

#include <iostream>
using namespace std;
int main ()
{

    int day = 0;



    do
    {
        day++;


    switch(day)
    {
    case 1:
        {
        cout<<"A partridge in a peartree."<<endl<<endl;
    break;
        }

    case 2:
        {
        cout<<"On the second day of Al Eid my true love gave to me,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree."<<endl<<endl;
    break;
        }

    case 3:
        {
        cout<<"On the third day of Al Eid my true love gave to me,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;
        }

    case 4:
        {
        cout<<"On the fourth day of Al Eid my true love gave to me,"<<endl
            <<"Four calling birds,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;
        }

    case 5:
        {
        cout<<"On the fifth day of Al Eid my true love gave to me,"<<endl
            <<"Five golden rings,"<<endl
            <<"Four calling birds,"<<endl
            <<"Three french hens,"<<endl
            <<"Two turtle doves, and"<<endl
            <<"A partridge in a peartree"<<endl<<endl;
    break;  
    default:   
    break;

        }
    }
}while (day<=5);


return 0;
}

OK :D

i didn't understand that i need to output one day in each switch statemet :S

I said switch *case* with the emphasis. Not switch statement. But after looking at your screenshot, I see that the way you have it is correct.

Thnx a lot..
ur so sweet for helping me :)

Thnx a lot..
ur so sweet for helping me :)

your welcome.

@above code-there is no need to put any open/close paranthesis iniside each case statements...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.