已經在這項任務上工作了20多個小時,並且我理解人們出於某種原因從不想幫助完成家庭作業,但我從字面上看不到任何地方,並且認爲我會至少嘗試並要求幫助,因爲我曾嘗試在多個論壇上無濟於事。我的代碼如下...日曆在C編程語言作業
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int getdaycode(int month, int year);
void printheader(int month, int year);
int getndim(int month, int year);
int main()
{
\t int day, month, year, nummonths;
\t {
\t \t printf("Enter Month, Year, and Number of Months");
\t \t scanf("%d %d %d", &month, &year, &nummonths);
\t \t
\t \t for (nummonths; nummonths < 13; nummonths++)
\t \t \t if (nummonths > 13)
\t \t \t \t year = year + 1;
\t \t printheader(month, year);
\t \t int numdays = getndim(month, year);
\t \t int daycode = getdaycode(month, year);
\t \t
\t \t for (day = 1; day <= 1 + daycode * 4; day++)
\t \t \t printf(" ");
\t \t
\t \t for (day = 1; day <= numdays; day++)
\t \t
\t \t {
\t \t \t printf("%2d", day);
\t \t \t if ((day + daycode) % 7 > 0)
\t \t \t \t printf(" ");
\t \t \t else
\t \t \t \t printf("\n");
\t \t }
\t \t daycode = (daycode + numdays) % 7;
\t }
}
int getdaycode(int month, int year)
{
\t int numdays;
\t {
\t \t numdays = ((year - 1) * 365 + ((year - 1)/4) - ((year - 1)/100) + ((year - 1)/400)); // how many days including exceptions
\t \t if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) \t \t //check if leapyear
\t \t {
\t \t \t if (month == 1) \t \t \t \t \t \t \t // January
\t \t \t \t numdays = numdays;
\t \t \t if (month == 2) \t \t \t \t \t \t \t // February
\t \t \t \t numdays = numdays + 31;
\t \t \t if (month == 3) \t \t \t \t \t \t \t // March
\t \t \t \t numdays = numdays + 28 + 31 + 1;
\t \t \t if (month == 4) \t \t \t \t \t \t \t // April
\t \t \t \t numdays = numdays + 31 + 28 + 31 + 1;
\t \t \t if (month == 5) \t \t \t \t \t \t \t // May
\t \t \t \t numdays = numdays + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 6) \t \t \t \t \t \t \t // June
\t \t \t \t numdays = numdays + 31 + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 7) \t \t \t \t \t \t \t // July
\t \t \t \t numdays = numdays + 30 + 31 + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 8) \t \t \t \t \t \t \t // August
\t \t \t \t numdays = numdays + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 9) \t \t \t \t \t \t \t // September
\t \t \t \t numdays = numdays + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 10) \t \t \t \t \t \t \t // October \t \t \t \t \t \t
\t \t \t \t numdays = numdays + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 11) \t \t \t \t \t \t \t // November
\t \t \t \t numdays = numdays + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
\t \t \t if (month == 12) \t \t \t \t \t \t \t // December
\t \t \t \t numdays = numdays + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
\t \t }
\t \t else
\t \t {
\t \t \t if (month == 1) \t \t \t \t \t \t \t // January
\t \t \t \t numdays = numdays;
\t \t \t if (month == 2) \t \t \t \t \t \t \t // February
\t \t \t \t numdays = numdays + 31;
\t \t \t if (month == 3) \t \t \t \t \t \t \t // March
\t \t \t \t numdays = numdays + 28 + 31;
\t \t \t if (month == 4) \t \t \t \t \t \t \t // April
\t \t \t \t numdays = numdays + 31 + 28 + 31;
\t \t \t if (month == 5) \t \t \t \t \t \t \t // May
\t \t \t \t numdays = numdays + 30 + 31 + 28 + 31;
\t \t \t if (month == 6) \t \t \t \t \t \t \t // June
\t \t \t \t numdays = numdays + 31 + 30 + 31 + 28 + 31;
\t \t \t if (month == 7) \t \t \t \t \t \t \t // July
\t \t \t \t numdays = numdays + 30 + 31 + 30 + 31 + 28 + 31;
\t \t \t if (month == 8) \t \t \t \t \t \t \t // August
\t \t \t \t numdays = numdays + 31 + 30 + 31 + 30 + 31 + 28 + 31;
\t \t \t if (month == 9) \t \t \t \t \t \t \t // September
\t \t \t \t numdays = numdays + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
\t \t \t if (month == 10) \t \t \t \t \t \t \t // October \t \t \t \t \t \t
\t \t \t \t numdays = numdays + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
\t \t \t if (month == 11) \t \t \t \t \t \t \t // November
\t \t \t \t numdays = numdays + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
\t \t \t if (month == 12) \t \t \t \t \t \t \t // December
\t \t \t \t numdays = numdays + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
\t \t }
\t \t int daycode = numdays % 7;
\t \t switch (daycode)
\t \t {
\t \t case 0:
\t \t \t printf("Sunday\n");
\t \t \t break;
\t \t case 1:
\t \t \t printf("Monday\n");
\t \t \t break;
\t \t case 2:
\t \t \t printf("Tuesday\n");
\t \t \t break;
\t \t case 3:
\t \t \t printf("Wednesday\n");
\t \t \t break;
\t \t case 4:
\t \t \t printf("Thursday\n");
\t \t \t break;
\t \t case 5:
\t \t \t printf("Friday\n");
\t \t \t break;
\t \t case 6:
\t \t \t printf("Saturday\n");
\t \t \t break;
\t \t default: printf("unexpected error (daycode case) daycode = %d", daycode);
\t \t \t break;
\t \t }
\t \t return daycode;
\t }
}
void printheader(int month, int year)
\t {
\t \t \t printf("%14d %1d\n", month, year);
\t \t \t printf("Sun ");
\t \t \t printf("Mon ");
\t \t \t printf("Tue ");
\t \t \t printf("Wed ");
\t \t \t printf("Thu ");
\t \t \t printf("Fri ");
\t \t \t printf("Sat\n");
\t \t }
int getndim(int month, int year)
{
\t int numdays;
\t if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) \t \t //check if leapyear
\t {
\t \t if (month == 1) \t \t \t \t \t \t \t // January
\t \t \t numdays = 31;
\t \t if (month == 2) \t \t \t \t \t \t \t // February
\t \t \t numdays = 29;
\t \t if (month == 3) \t \t \t \t \t \t \t // March
\t \t \t numdays = 31;
\t \t if (month == 4) \t \t \t \t \t \t \t // April
\t \t \t numdays = 30;
\t \t if (month == 5) \t \t \t \t \t \t \t // May
\t \t \t numdays = 31;
\t \t if (month == 6) \t \t \t \t \t \t \t // June
\t \t \t numdays = 30;
\t \t if (month == 7) \t \t \t \t \t \t \t // July
\t \t \t numdays = 31;
\t \t if (month == 8) \t \t \t \t \t \t \t // August
\t \t \t numdays = 31;
\t \t if (month == 9) \t \t \t \t \t \t \t // September
\t \t \t numdays = 30;
\t \t if (month == 10) \t \t \t \t \t \t \t // October \t \t \t \t \t \t
\t \t \t numdays = 31;
\t \t if (month == 11) \t \t \t \t \t \t \t // November
\t \t \t numdays = 30;
\t \t if (month == 12) \t \t \t \t \t \t \t // December
\t \t \t numdays = 31;
\t }
\t else
\t {
\t \t if (month == 1) \t \t \t \t \t \t \t // January
\t \t \t numdays = 31;
\t \t if (month == 2) \t \t \t \t \t \t \t // February
\t \t \t numdays = 28;
\t \t if (month == 3) \t \t \t \t \t \t \t // March
\t \t \t numdays = 31;
\t \t if (month == 4) \t \t \t \t \t \t \t // April
\t \t \t numdays = 30;
\t \t if (month == 5) \t \t \t \t \t \t \t // May
\t \t \t numdays = 31;
\t \t if (month == 6) \t \t \t \t \t \t \t // June
\t \t \t numdays = 30;
\t \t if (month == 7) \t \t \t \t \t \t \t // July
\t \t \t numdays = 31;
\t \t if (month == 8) \t \t \t \t \t \t \t // August
\t \t \t numdays = 31;
\t \t if (month == 9) \t \t \t \t \t \t \t // September
\t \t \t numdays = 30;
\t \t if (month == 10) \t \t \t \t \t \t \t // October \t \t \t \t \t \t
\t \t \t numdays = 31;
\t \t if (month == 11) \t \t \t \t \t \t \t // November
\t \t \t numdays = 30;
\t \t if (month == 12) \t \t \t \t \t \t \t // December
\t \t \t numdays = 31;
\t }
\t return numdays;
}
我想知道的是如何正確地調用我的getdaycode功能爲我的主要功能。此外,當這不是問題時,這一天繼續出現在我的標題下方,它隨着排列日曆的日子排序而混亂。這是我在這一點上最大的兩個問題,我真的很喜歡和某人一起工作......真的很困惑......並且在你回憶你的材料之前......我是編程時沒有背景的全新人物,以及本課程不提供任何資源,例如書籍或網站以供參考。 (這使得極其困難)。任何幫助非常感謝!
「我理解人們出於某種原因從來沒有想幫助做家庭作業「 - 這是不正確的。人們不想要的是爲懶蟲編寫代碼。 [這裏是](http://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions)在家庭作業上接受的政策:不解決,做*幫助*解決。至於你的問題,多一點細節會很好。例如,「如何正確地將我的getdaycode函數調用到我的主函數中」 - 現在你調用它的方式有什麼問題? – Amadan
「這一天一直顯示在我的標題下方,它與混亂日曆的日子的順序混亂」 - 在你的問題中顯示輸出,不要讓人編譯 - 並顯示你將如何*喜歡* (以防止我們猜測你想要什麼)。描述該程序是什麼*爲*。一個很好的問題是獲得很好的答案。 – Amadan
我不知道如何發佈我的輸出/調試過程中顯示的結果 – tyooo