c++ - 12 Days Of Christmas C Program -


so tried coding 12 days of christmas myself. i'm not yet done though lyrics, i'm still trying figure out. don't understand why "1st day" of christmas gets doubled , partnered different gift , on 12th day, no gift showing up. checked on switch case , seem right guess. , possible lessen code print out complete lyrics?

#include <stdio.h> #include <conio.h>  int main() // main function {     int days, counter, num;     //int counter = 1;        printf("\t\t***twelve days of christmas***\n");     printf("\t\t______________________________\n\n\n");      (counter=0; counter<=12; counter++)     {            // counter++;         switch(counter)         {             case 1: printf("\t\ta partridge in pear tree\n");break; // day 12             case 2: printf("\t\ttwo turtle doves\n"); break;             case 3: printf("\t\tthree french hens\n"); break;             case 4: printf("\t\tfour calling birds \n"); break;             case 5: printf("\t\tfive golden rings\n"); break;             case 6: printf("\t\tsix geese laying\n"); break;             case 7: printf("\t\tseven swans swimming\n"); break;             case 8: printf("\t\teight maids milking\n"); break;             case 9: printf("\t\tnine ladies dancing\n"); break;             case 10: printf("\t\tten lords leaping\n"); break;             case 11: printf("\t\televen pipers piping\n"); break;             case 12: printf("\t\ttwelve drummers drumming\n"); break; // day 1          }         printf("\n\ton ");          switch(counter){             case 1:                 printf("1st");                 break;               case 2:                  printf("2nd");                 break;             case 3:                  printf("3rd");                 break;             case 4:                  printf("4th");                 break;             case 5:                  printf("5th");                 break;                   case 6:                  printf("6th");                 break;             case 7:                  printf("7th");                 break;             case 8:                  printf("8th");                 break;               case 9:                  printf("9th");                 break;             case 10:                     printf("10th");                 break;               case 11:                     printf("11th");                 break;               case 12:                     printf("12th");                 break;                                                                                                       default:                  printf("1st", num);                 break;             }             printf(" day of christmas true love sent me\n");          }             getch();         return 0;     } 

and instructions says, "your function invoked in main() function , not return anything" mean not make more functions? or should place of codes inside main function only? or create separate codes?

look switch statement again, , remember breaks not necessary.

switch (day) {   case 2: printf("two turtle doves ");   case 1: printf("and partridge in pear tree"); } 

this have "day 2" start @ "two turtle doves" , fall through "and partridge in pear tree".

meanwhile, "day 1" starts "and partridge in pear tree".


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -