I have been working on this program as an assignment for more than 15+ hours, it is already more than 3 days past due and this isn't due to me simply being lazy... I have litterally put SOO many hours into trying to understand how to get the outcome necessary and considering this you would think I would get closer, however this is not the case. I am at a stand still and extremely new when it comes to programming which seems like this assignment is pretty cruel and unusual to someone who has never programmed in their lives before. My ranting aside... The program that has been causing so much stress is as follows...
Code:
#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()
{
int day, month, year, nummonths;
{
printf("Enter Month, Year, and Number of Months");
scanf("%d %d %d", &month, &year, &nummonths);
for (nummonths; nummonths < 13; nummonths++)
if (nummonths > 13)
year = year + 1;
printheader(month, year);
int numdays = getndim(month, year);
int daycode = getdaycode(month, year);
for (day = 1; day <= 1 + daycode * 1; day++)
printf(" ");
for (day = 1; day <= numdays; day++)
{
printf("%4d", day);
if (daycode % 7 > 0)
printf(" ");
else
printf("\n");
}
daycode = numdays % 7;
}
}
int getdaycode(int month, int year)
{
int numdays;
{
numdays = ((year - 1) * 365 + ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1) / 400)); // how many days including exceptions
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) //check if leapyear
{
if (month == 1) // January
numdays = numdays;
if (month == 2) // February
numdays = numdays + 31;
if (month == 3) // March
numdays = numdays + 28 + 31 + 1;
if (month == 4) // April
numdays = numdays + 31 + 28 + 31 + 1;
if (month == 5) // May
numdays = numdays + 30 + 31 + 28 + 31 + 1;
if (month == 6) // June
numdays = numdays + 31 + 30 + 31 + 28 + 31 + 1;
if (month == 7) // July
numdays = numdays + 30 + 31 + 30 + 31 + 28 + 31 + 1;
if (month == 8) // August
numdays = numdays + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
if (month == 9) // September
numdays = numdays + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
if (month == 10) // October
numdays = numdays + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
if (month == 11) // November
numdays = numdays + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
if (month == 12) // December
numdays = numdays + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
}
else
{
if (month == 1) // January
numdays = numdays;
if (month == 2) // February
numdays = numdays + 31;
if (month == 3) // March
numdays = numdays + 28 + 31;
if (month == 4) // April
numdays = numdays + 31 + 28 + 31;
if (month == 5) // May
numdays = numdays + 30 + 31 + 28 + 31;
if (month == 6) // June
numdays = numdays + 31 + 30 + 31 + 28 + 31;
if (month == 7) // July
numdays = numdays + 30 + 31 + 30 + 31 + 28 + 31;
if (month == 8) // August
numdays = numdays + 31 + 30 + 31 + 30 + 31 + 28 + 31;
if (month == 9) // September
numdays = numdays + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
if (month == 10) // October
numdays = numdays + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
if (month == 11) // November
numdays = numdays + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
if (month == 12) // December
numdays = numdays + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
}
int daycode = numdays % 7;
switch (daycode)
{
case 0:
printf("Sunday\n");
break;
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
default: printf("unexpected error (daycode case) daycode = %d", daycode);
break;
}
return daycode;
}
}
void printheader(int month, int year)
{
printf("%14d %1d\n", month, year);
printf("Sun ");
printf("Mon ");
printf("Tue ");
printf("Wed ");
printf("Thu ");
printf("Fri ");
printf("Sat\n");
}
int getndim(int month, int year)
{
int numdays;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) //check if leapyear
{
if (month == 1) // January
numdays = 31;
if (month == 2) // February
numdays = 29;
if (month == 3) // March
numdays = 31;
if (month == 4) // April
numdays = 30;
if (month == 5) // May
numdays = 31;
if (month == 6) // June
numdays = 30;
if (month == 7) // July
numdays = 31;
if (month == 8) // August
numdays = 31;
if (month == 9) // September
numdays = 30;
if (month == 10) // October
numdays = 31;
if (month == 11) // November
numdays = 30;
if (month == 12) // December
numdays = 31;
}
else
{
if (month == 1) // January
numdays = 31;
if (month == 2) // February
numdays = 28;
if (month == 3) // March
numdays = 31;
if (month == 4) // April
numdays = 30;
if (month == 5) // May
numdays = 31;
if (month == 6) // June
numdays = 30;
if (month == 7) // July
numdays = 31;
if (month == 8) // August
numdays = 31;
if (month == 9) // September
numdays = 30;
if (month == 10) // October
numdays = 31;
if (month == 11) // November
numdays = 30;
if (month == 12) // December
numdays = 31;
}
return numdays;
}
The 3 functions that follow the main all work as they are intended. However the problem is I don't know how to make them interact within the main function to follow the lines of code as I have placed them. I am simply trying to use my functions of Getdaycode which finds out the day of the week and multiplying this daycode value from it's function by the starting day of the month specified by a scanf("%d %d", &month, &year). The second function is simply my header which I wanted to be the top of my calendar which should have the month NAME instead of the number value I keep getting along with the year, above a row of the days marked in 3 letter abbreviations. The final function is Getnumber of days in month. This will basically just mark the months of the year and mark how many days are in each of these months. If it is a leap year February will have 29 days instead of 28 is basically the only exception here. So again these 3 functions should be working fine, at least mostly. My biggest problem is my main code. (I'm away of the mess of a code this is but still I am pretty sick of it and would REALLY appreciate any help on the matter).