Q:

Calendar In C Programming Language Assignment

Have been working on this assignment for 20+ hours and I understand people for some reason never want to help with homework assignments but I literally am not getting anywhere and figured I would at least TRY and ask for help because I have tried on multiple forums to no avail. My code is as follows...

#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 * 4; day++)
   printf(" ");
  
  for (day = 1; day <= numdays; day++) 
  
  {
   printf("%2d", day);
   if ((day + daycode) % 7 > 0)

    printf("   ");
   else
    printf("\n");
  }
  daycode = (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;
}

What I am wondering is how to call my getdaycode function correctly into my main function. Also, when that isn't the problem, the day keeps showing up below my header and it messes with the ordering of the days messing up the calendar. Those are my two biggest problems at this point, I really would enjoy working through this with someone... Really confused.. and before you say look back at your material.. I am brand new at programming with no background, as well as this course didn't come with any sources such as books or sites to reference. (This makes it EXTREMELY difficult). Any help Greatly Appreciated!

A:

it may help and useful for you .     
int main()
{
int  day, month, year, nummonths;
    printf("Enter Month, Year, and Number of Months");
    scanf("%d %d %d", &month, &year, &nummonths);
    if (nummonths > 12)
        year = year + nummonths%12;

    printheader(month, year);
    int numdays = getndim(month, year);
    int daycode = getdaycode(month, day, year);

   for (day = 1; day <= numdays; day++) 
    {   printf("%4d", day);
        if (day % 7 > 0)
            printf("\t");
        else
            printf("\n");
    }
}

but apart form solution of that specific problem you need work on some skills that can help you .
Please prefer some book and online resources and complete any one of them 
1> Book :- let us c ,By:- balaguruswami   
2> Tutorials http://www.w3schools.in/c/intro/
3> Tutorials http://www.tutorialspoint.com/cprogramming/

