一個C程序,它包含一個輸出傳統聖誕歌曲「十二日聖誕節」的歌詞的功能。不要手動輸出整個歌詞。12天的聖誕節C功能的程序
所以我做了一個代碼,有錯誤,但我終於修好了。我的十二天聖誕歌曲循環播放效果很好。
但我有另一個問題。我的代碼是否可以作爲函數分離或解析?
指令說:「你的函數只會在main()函數中被調用,並且不會返回任何東西。」所以我想我會使用void?以什麼方式?
#include <stdio.h>
#include <conio.h>
int main() // Main Function
{
int days, counter, num;
printf("\n\t\t* * * TWELVE DAYS OF CHRISTMAS * * *\n");
printf("\t\t_____________________________________\n\n\n");
for (counter=1; counter<=12; counter++) {
printf("\tOn the ");
switch(counter){
case 1:
printf("1st");
break;
case 2:
printf("2nd");
break;
case 3:
printf("3rd");
break;
default:
printf("%dth", counter);
break;
}
printf(" day of Christmas my true love sent to me\n\n");
switch(counter) {
case 12: printf("\t\tTwelve Drummers Drumming\n\n");
case 11: printf("\t\tEleven Pipers Piping\n\n");
case 10: printf("\t\tTen Lords a Leaping\n\n");
case 9: printf("\t\tNine Ladies Dancing\n\n");
case 8: printf("\t\tEight Maids a Milking\n\n");
case 7: printf("\t\tSeven Swans a Swimming\n\n");
case 6: printf("\t\tSix Geese a Laying\n\n");
case 5: printf("\t\tFive Golden Rings\n\n");
case 4: printf("\t\tFour Calling Birds \n\n");
case 3: printf("\t\tThree French Hens\n\n");
case 2: printf("\t\tTwo Turtle Doves\n\n");
case 1: printf("\t\t");if (counter > 1) printf("And ");printf("A Partridge in a Pear Tree\n\n");
// case 1: printf("\t\tA Partridge in a Pear Tree\n\n");
}
}
getchar(); return 0; }
試圖執行此操作,並與打印工作正常。你有任何建議,以imporove我的代碼?遇到功能問題。
你一直由C混淆比賽的啓發,整個項目在三條線上? – matcheek
我已經刪除了C++標記,因爲代碼中沒有C++標記。 –
你的第二個'switch'語句沒有'break',這是一個錯誤。它是如何打印你想要的? – Thanushan