Question

Can someone fix my coding please it's a calendar some days are placed wrong. I just...

Can someone fix my coding please it's a calendar some days are placed wrong. I just want the Main menu to display first and second option and four option to end the program properly. Please remove option number 3 Find the number of days between 2 selected dates and the code that belongs to this function.

#include<stdio.h>

void days(int,int,int,int,int,int);

int month(int,int);

int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};

#define TRUE 1

#define FALSE 0

int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

char *months[]=

{

" ",

"\n\n\nJanuary",

"\n\n\nFebruary",

"\n\n\nMarch",

"\n\n\nApril",

"\n\n\nMay",

"\n\n\nJune",

"\n\n\nJuly",

"\n\n\nAugust",

"\n\n\nSeptember",

"\n\n\nOctober",

"\n\n\nNovember",

"\n\n\nDecember"

};

int inputyear(void)

{

int year;

printf("Enter Year: ");

scanf("%d", &year);

return year;

}

int inputmonth(void)

{

int month;

printf("Enter a month (1-12): ");

scanf("%d", &month);

return month;

}

int determinedaycode(int year)

{

int daycode;

int d1, d2, d3;

d1 = (year - 1.)/ 4.0;

d2 = (year - 1.)/ 100.;

d3 = (year - 1.)/ 400.;

daycode = (year + d1 - d2 + d3) %7;

return daycode;

}

int determineleapyear(int year)

{

if(year% 4 == FALSE & year%100 != FALSE || year%400 == FALSE)

{

days_in_month[2] = 29;

return TRUE;

}

else

{

days_in_month[2] = 28;

return FALSE;

}

}

void calendar(int year, int daycode)

{

int month, day;

for ( month = 1; month <= 12; month++ )

{

printf("%s", months[month]);

printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );

// Correct the position for the first date

for ( day = 1; day <= 1 + daycode * 5; day++ )

{

printf(" ");

}

// Print all the dates for one month

for ( day = 1; day <= days_in_month[month]; day++ )

{

printf("%2d", day );

// Is day before Sat? Else start next line Sun.

if ( ( day + daycode ) % 7 > 0 )

printf(" " );

else

printf("\n " );

}

// Set position for next month

daycode = ( daycode + days_in_month[month] ) % 7;

}

}

void calendarm(int year, int daycode, int month)

{

int day;

printf("%s", months[month]);

printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );

// Correct the position for the first date

for ( day = 1; day <= 1 + daycode * 5; day++ )

{

printf(" ");

}

// Print all the dates for one month

for ( day = 1; day <= days_in_month[month]; day++ )

{

printf("%2d", day );

// Is day before Sat? Else start next line Sun.

if ( ( day + daycode ) % 7 > 0 )

printf(" " );

else

printf("\n " );

}

// Set position for next month

daycode = ( daycode + days_in_month[month] ) % 7;

}

int main(void)

{

int year, daycode, leapyear,month,c;

int a1,b1,c1,a2,b2,c2;

printf("\n MAIN MENU");

printf("\n 1.View calendar for specified month in selected year");

printf("\n 2.View the calendar for the specified year");

printf("\n 3.Find the number of days between 2 selected dates");

printf("\n 4.End the program \n");

scanf("%d",&c);

switch(c)

{

case 1:

year = inputyear();

month = inputmonth();

daycode = determinedaycode(year);

determineleapyear(year);

calendarm(year, daycode,month);

printf("\n");break;

case 2:

year = inputyear();

daycode = determinedaycode(year);

determineleapyear(year);

calendar(year, daycode);

printf("\n");break;

case 3:


printf("\n Enter first date(dd mm yyyy) : ");

scanf("%d%d%d",&a1,&b1,&c1);

printf("\n Enter second date(dd mm yyyy) : ");

scanf("%d%d%d",&a2,&b2,&c2);

if(c2>=c1)

days(c1,c2,b1,b2,a1,a2);

else

days(c2,c1,b2,b1,a2,a1);

break;

case 4: break;

default:printf("\n Enter correct value");break;


}

}

void days(int y1,int y2,int m1,int m2,int d1,int d2)

{

int count=0,i;

for(i=y1;i<y2;i++)

{

if(i%4==0)

count+=366;

else

count+=365;

}

count-=month(m1,y1);

count-=d1;

count+=month(m2,y2);

count+=d2;

if(count<0)

count=count*-1;

printf("\n The no. of days b/w the 2 dates = %d days",count);

}

int month(int a,int yy)

{

int x=0,c;

for(c=0;c<a-1;c++)

{

if(c==1)

{

if(yy%4==0)

x+=29;

else

x+=28;

}

else

x+=mon[c];

}

return(x);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM CODE (Option-3 removed and also its functions code)

#include<stdio.h>

// Removing days and month function declarations (I am just commenting below line, so u can remove it)
// void days(int,int,int,int,int,int);
// int month(int,int);

int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};

#define TRUE 1
#define FALSE 0

int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

char *months[]=
{
   " ",  
   "\n\n\nJanuary",  
   "\n\n\nFebruary",  
   "\n\n\nMarch",  
   "\n\n\nApril",  
   "\n\n\nMay",  
   "\n\n\nJune",  
   "\n\n\nJuly",  
   "\n\n\nAugust",  
   "\n\n\nSeptember",  
   "\n\n\nOctober",  
   "\n\n\nNovember",
   "\n\n\nDecember"
};

int inputyear(void)
{
   int year;
  
   printf("Enter Year: ");
  
   scanf("%d", &year);
  
   return year;
}

int inputmonth(void)
{
   int month;
  
   printf("Enter a month (1-12): ");
  
   scanf("%d", &month);
  
   return month;
}

int determinedaycode(int year)
{
   int daycode;
  
   int d1, d2, d3;
  
   d1 = (year - 1.)/ 4.0;
  
   d2 = (year - 1.)/ 100.;
  
   d3 = (year - 1.)/ 400.;
  
   daycode = (year + d1 - d2 + d3) %7;
  
   return daycode;
}

int determineleapyear(int year)
{
   if(year% 4 == FALSE & year%100 != FALSE || year%400 == FALSE)
  
   {  
       days_in_month[2] = 29;
      
       return TRUE;
   }
   else
   {
       days_in_month[2] = 28;
      
       return FALSE;
   }
}

void calendar(int year, int daycode)
{
   int month, day;
  
   for ( month = 1; month <= 12; month++ )
   {
       printf("%s", months[month]);
      
       printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );
      
       // Correct the position for the first date
      
       for ( day = 1; day <= 1 + daycode * 5; day++ )
       {
           printf(" ");
       }
  
       // Print all the dates for one month
      
       for ( day = 1; day <= days_in_month[month]; day++ )
       {
           printf("%2d", day );
           // Is day before Sat? Else start next line Sun.
          
           if ( ( day + daycode ) % 7 > 0 )
               printf(" " );
          
           else
               printf("\n " );  
       }
       // Set position for next month
      
       daycode = ( daycode + days_in_month[month] ) % 7;
   }
}

void calendarm(int year, int daycode, int month)
{

   int day;
  
   printf("%s", months[month]);
  
   printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );
  
   // Correct the position for the first date
  
   for ( day = 1; day <= 1 + daycode * 5; day++ )
  
   {
  
   printf(" ");
  
   }
  
   // Print all the dates for one month
  
   for ( day = 1; day <= days_in_month[month]; day++ )
  
   {
  
   printf("%2d", day );
  
   // Is day before Sat? Else start next line Sun.
  
   if ( ( day + daycode ) % 7 > 0 )
  
   printf(" " );
  
   else
  
   printf("\n " );
  
   }
  
   // Set position for next month
  
   daycode = ( daycode + days_in_month[month] ) % 7;
}

int main(void)
{
   int year, daycode, leapyear,month,c;
  
   // Removing unwanted variables
   // int a1,b1,c1,a2,b2,c2;
  
   // Writing using a loop giving user choices as many times as he wants
  
   while(c != 3)
   {
       printf("\n MAIN MENU");
  
       printf("\n 1.View calendar for specified month in selected year");
      
       printf("\n 2.View the calendar for the specified year");
      
       // Removing option 3 so option-4 "End the program" will become optin-3
      
       printf("\n 3.End the program \n ");
      
       scanf(" %d",&c);
      
       switch(c)
      
       {
           case 1:
          
               year = inputyear();
              
               month = inputmonth();
              
               daycode = determinedaycode(year);
              
               determineleapyear(year);
              
               calendarm(year, daycode,month);
              
               printf("\n");break;
              
           case 2:
          
               year = inputyear();
              
               daycode = determinedaycode(year);
              
               determineleapyear(year);
              
               calendar(year, daycode);
              
               printf("\n");break;
              
           // Removing whole case-3 details and making case-4, case-3
          
           case 3: break;
          
           default:printf("\n Enter correct value");break;
       }  
   }  
}

// Also definitions of days and month functions are removed  

SAMPLE OUTPUT

MAIN MENU 1. View calendar for specified month in selected year 2.view the calendar for the specified year 3. End the program

May Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 NPP лою в J

September Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 Octo

----------------------------------------------------------------------------------------------

COMMENT DOWN FOR ANY QUESTIONS...........
HIT A THUMBS UP IF YOU DO LIKE IT!!!

Add a comment
Know the answer?
Add Answer to:
Can someone fix my coding please it's a calendar some days are placed wrong. I just...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a part...

    Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a particular date (also your choosing) with an asterisk. Make sure the calendar displays the week, the days of the week and the year. Make sure the MSU Programming Class appears in the title of the Calendar. I will choose May 1st for the month and date. The code below is what I will be using. Please show where I can go to in...

  • In C programming. How do you build a calendar? I can't get the days to work...

    In C programming. How do you build a calendar? I can't get the days to work right. This is what I have so far #include <stdio.h> #include <string.h> #include <stdlib.h> int dow(int year, int month, int day) {     static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};     year -= month < 3;     return (year + year/4 - year/100 + year/400 + t[month-1] + day) % 7; } int main() {...

  • please rewrite or convert this C program into Assembly language and please make a notice of...

    please rewrite or convert this C program into Assembly language and please make a notice of which function is which! #include <stdio.h> #include <stdlib.h> void printMonthYear(int mon,int year); void printDaysOfWeek(); void printDays(int mon,int year); int getFirstDayOfMonth(int mon, int year); int getNumOfDaysInMonth(int mon, int year); int main(void) {    int mon=-1; int year= -1; printf("Month : "); fflush(stdout); scanf("%d",&mon);    if(mon < 1|| mon > 12){ printf("Invalid month >.<!: %d ! Must be between 1 and 12\n",mon); return 1; } printf("Year...

  • Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender {...

    Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }    public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...

  • Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then...

    Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class. (Code given below) import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayList<Month> months; private int number; public Year() { this(2013); } public Year(int number) { this.number = number;...

  • C LANGUAGE I just need the void push() function, which inserts new node to the front...

    C LANGUAGE I just need the void push() function, which inserts new node to the front of the list #include<stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; } Node; //Creating head a as a global Node* Node *head; /* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter (Node * prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf ("the given...

  • /* I want to fix void make_flight(int counter, flight_t flights[]) Enter flight code> Enter departure info...

    /* I want to fix void make_flight(int counter, flight_t flights[]) Enter flight code> Enter departure info for the flight leaving SYD. Enter month, date, hour and minute separated by spaces> Enter arrival city code> Enter arrival info. Enter month, date, hour and minute separated by spaces> It should do all of this: 1-Flight - left aligned, MAX_FLIGHTCODE_LEN (i.e. 6) chars at most. 2-City - left aligned, MAX_CITYCODE_LEN 3 chars at most . For example( VA1 or LAX ) 3- Month,...

  • Can someone help me fix my C code. I am getting segmentation fault along with missing...

    Can someone help me fix my C code. I am getting segmentation fault along with missing termination " /* These are the included libraries. */ #include #include #include #include void printTriangle(char *str); int main() { char sentence[81]; int done = 0; while(done != 1) { printf("Please enter the sentence or quit: "); fgets(sentence, 80, stdin); if(strcmp(sentence, "quit") == 0) done = 1; else printTriangle(sentence); } } void printTriangle(char *str) { int index = 0; int line = 1; int i;...

  • Can someone please help me. i keep getting an error in my code. I need it...

    Can someone please help me. i keep getting an error in my code. I need it to be on three seperate files! attached is my assignment and my code. c++ The class date Type implements the date in a program. Write the class functions as specified in the UML class diagram. The values for the month, day, and year should be validated (in the class functions) before storing the date into the data members. Set the invalid member data to...

  • Please create a C++ class called myDate. It should have the following operations: myDate() – default...

    Please create a C++ class called myDate. It should have the following operations: myDate() – default constructor. This will set the date to May 10, 1959. myDate(int M, int D, int Y) – overloaded constructor. This will set the date to the values passed in through the parameter list represented by Month, Day and Year. void display() – display the date in the following format (May 11, 1959) Do NOT print a linefeed after the date. void incrDate(int N) –...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT