所以我尝试自己编写 12 天的圣诞节。我还没有完成歌词,但我仍在努力弄清楚。但我不明白为什么我圣诞节的“第一天”会翻倍并搭配不同的礼物,而在第 12 天,没有礼物出现。我检查了我的开关盒,我猜它们似乎是对的。有没有可能我可以减少我的代码来打印出完整的歌词?
#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");
for (counter=0; counter<=12; counter++)
{
// counter++;
switch(counter)
{
case 1: printf("\t\tA Partridge in a 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 a Laying\n"); break;
case 7: printf("\t\tSeven Swans a Swimming\n"); break;
case 8: printf("\t\tEight Maids a Milking\n"); break;
case 9: printf("\t\tNine Ladies Dancing\n"); break;
case 10: printf("\t\tTen Lords a 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 the ");
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 my true love sent to me\n");
}
getch();
return 0;
}
指令说,“你的函数只会在 main() 函数中被调用,不会返回任何东西” 那么这是否意味着我不会创建更多函数?或者我应该只将我的所有代码放在主函数中吗?还是创建单独的代码?