所以我尝试自己编码圣诞节的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()函数中被调用,并且将不返回任何内容”。这是否意味着我将不制作更多函数?还是应该将所有代码都只放置在main函数中?还是创建单独的代码?
再次查看switch语句,请记住,中断并不是完全必要的。
switch (day) {
case 2: printf("two turtle doves ");
case 1: printf("and a partridge in a pear tree");
}
这将以“第二天”开始于“两只海龟鸽子”,然后下降到“和梨树中的part”。
同时,“第1天”开始是“和梨树上的part”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句