switch statements

I don't want you to do my homework...just help me! Okay, writing the 12 days of Xmas song..

cout << "on the :;<br>
for (int i = 1; i <= 12; i++ )<br>
{

switch (i)

case 1 : cout << "FIRST ";<br>
break;

case 2 : cout << "SECOND ";<br>
break;

etc...

after case 12 cout << "day of Christmas...<br>
then I want another switch statement to insert the partridge, turtle doves and so on..right now it is printing

on the first day of Christmas

on the second day of Christmas and so on and then after the first 12 it is printing the insert part. How do I get the second switch statement inserted? I am a newbie so be kind!!

Thanks!


Comments

  • Oh how cute, you'll have to send me a copy (j/k :)



    Anyway, here is an example of how to use Switch:



    int Value = 0;



    switch (Value)

    {

    case 0:

    // Do something.

    break;

    case 1:

    // Do something else.

    break;

    case 2:

    // Do something more.

    break;

    default:

    // Everything else that isn't "cased."

    break;

    }



    The Value can not be a string, only a number datatype.



    -Xotor-



    : I don't want you to do my homework...just help me! Okay, writing the 12 days of Xmas song..

    : cout << "on the :;<br>
    : for (int i = 1; i <= 12; i++ )<br>
    : {

    : switch (i)

    : case 1 : cout << "FIRST ";<br>
    : break;

    : case 2 : cout << "SECOND ";<br>
    : break;

    : etc...

    : after case 12 cout << "day of Christmas...<br>
    : then I want another switch statement to insert the partridge, turtle doves and so on..right now it is printing

    : on the first day of Christmas

    : on the second day of Christmas and so on and then after the first 12 it is printing the insert part. How do I get the second switch statement inserted? I am a newbie so be kind!!

    : Thanks!

    :






  • I think you need to use the fall-through feature of case statements for this problem,

    switch ( i ) {

    case 12: ....

    ...

    case 3: cout << "three french hens,";<br>
    case 2: cout << "two turtle doves, and";<br>
    case 1: cout << "a partridge in a pear tree";<br>
    }




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories