Question
I'm kind of stuck on this problem. Can you fix the code to work well? It does not compile. This is a code. #include int
I'm kind of stuck on this problem. Can you fix the code to work well? It does not compile.
This is a code.
#include
int isLeapYear(int year);
int displayMenu(void);
void getCalenderDate(int &day, int &month, int &year);// prompts and gets calender date from user
void getJulianDate(int &days, int &year);// prompts and gets Julian date from user
void toCalender(int days, int year2, int &day, int &month, int &year1);// converts Julian date into calender date
void toJulian(int day, int month, int year1, int &days, int &year2);// converts calender date into Julian date
int daysBetweenDates(int days, int year2, int &day, int &month, int &year1);// calculates the number of days between two calender date
int main(void)
{
int Jyear = 1900;
int year1, year2, month1, month2, day1, day2;
int days;
int choice=0;
do
{
choice = displayMenu();
switch(choice)
{
case 1:
getCalenderDate(day1, month1, year1);
break;
case 2:
getJulianDate(day2, year2);
break;
case 3:
printf("Convert to Julian Date: ");
toJulian(day1, month1, year1, day2, year2);
printf("%d \t %d \t %d \t (%d, %d) ", day1, month1,year1, day2, year2); break;
case 4:
printf("Convert to Original Date: ");
toCalender(day2, year2, day1, month1, year1);
printf("%d \t %d \t\t (%d/%d/%d) ", day2, year2, day1, month1, year1);
break;
case 5:
getCalenderDate(day1, month1, year1);
getJulianDate(day2, year2);
days =daysBetweenDates(day2, year2, day, month, year1);
printf("%d \t %d \t %d %d %d %d ", day1, month1,year1, day2, year2, days);
break;
case 6:
exit(0);
}
}while(1);
// your code goes here
return 0;
}
//function to check whether it is leap year or not
int isLeapYear(int year)
{
return ((!(year %4) && (year % 100) || !(year % 400)));
}
//displays selection menu and promps user for selection
int displayMenu()
{
int choice=0;
while(choice6)
{
printf("DATE SELECTION MENU ");
printf("1) Convert calendar date into Julian date ");
printf("2) Convert Julian date into calendar date ");
printf("3) Compute days between two calender dates ");
printf("4) Exit program ");
printf("ENTER SELECTION (1 - 3): ");
scanf("%d",&choice);
printf(" ");
if(choice3)
printf("invalid entry ");
}
return choice;
}
void getCalenderDate(int &day, int &month, int &year)
{
printf("Enter date: ");
scanf("%d", &day);
printf("Enter month: ");
scanf("%d", &month);
printf("Enter year: ");
scanf("%d", &year);
}
void getJulianDate(int &days, int &year)
{
printf("Enter date: ");
scanf("%d", &days);
printf("Enter year: ");
scanf("%d", &year);
}
void toJulian(int day, int month, int year1, int &days, int &year2)
{
int daysinmonth;
int days=1,i;
for (i=1;i { switch(i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: daysinmonth=31; break; case 9: case 4: case 6: case 11: daysinmonth=30; break; case 2: daysinmonth=28 +isLeapYear(year); break; } days+=daysinmonth; //and count how many days passed } days+=day; //add to the day wanted year2 = year; } void toCalendar(int days, int year2, int &day, int &month, int &year1) { int i=0; int daysinmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(isLeapYear(year)==1) daysinmonth[1]++; while(days>daysinmonth[i]) { days=days-daysinmonth[i]; i++; } day = days; month = i; year1 = year2; } int daysBetweenDates(int days, int year2, int day, int month, int year1) { int days2=0, count=0, total =0, difference; toJulian(day1, month1, year1, day2, year2); if(year1>year2) { difference = year1-year2; for(int i = year2 ; i { if(isLeapYear(i)) count++; } } else { difference = year2-year1; for(int i = year1 ; i { if(isLeapYear(i)) count++; } } total = count + difference*365; return total; } This is a question. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started