Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I thought i solved this problem, but I just found out that it has buggy on leap

ID: 3626136 • Letter: I

Question

I thought i solved this problem, but I just found out that it has buggy on leap year.
Can anyone help me to modify this code by adding enum into it?
//header File
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;




enum monthdays {JAN=31,FEB=28,MAR=31,APR=30,MAY,JUN=30,JUL,AUG=31,SEP=30,OCT,NOV=30,DEC};

int main(void)
{
// Design Method:
// 1. There are 365 days in a year whcih means 52 weeks and 1 extra day Jan 1st Year 1 is Monday so Jan 1st Years 2 should be Tuesday
// so we need to find out how many leap year will be in the calendar from year 1.
// 2. Then we can use the method to calculate what day is in the firstday of each month.
// 3. There is leap year after each 4 years, there is no leap year when face every 100 years, and there is a leap year when faced 400 years

int i;
int remainder; // Calculate the left over of days of the first month,it means to calculate what day it is in first month
int year; // Calculate year
int monthdays; // Calculate month

// Define how many day in each month
int day[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dayrem; // discover the leftover in each Jan
ifstream fin;
ofstream fout;
fout.open("cal.txt");

cout << "Enter A Year¡G";
cin >> year;
cout << "Enter A Month¡G";
cin >> monthdays;
cout << endl << endl;

// We know Jan. 1st year 1 is Monday
remainder = (year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7;
// We need to calculate leap years to calculate how many leftover in first month
// If it can be divided by 100 then its not a leap year but if it can be divided by 400 then its leap year
// Calculate the day before a Dec. 31 from the year u asked
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{// if it is leap year the leftover +1 and Feb. has 29 day now
if (monthdays >= 28)
{ monthdays == 28;
}//end leap year
}//end Feb in leap year
// calculate how many days total in the year you ask
for (i = 0; i < (monthdays - 1); i++)
{
remainder += day[i];
}
// calculate whcih day it is in the month u ask but because we calculate from Sunday so + 1
dayrem = (remainder + 1) % 7;

cout << "**********AD: " << year<<"*********"<<"MONTH: " << monthdays <<"**********"<< endl;
fout << "**********AD: " << year<<"*********"<<"MONTH: " << monthdays <<"**********"<< endl;
cout << "===SUN===MON===TUE===WED===THU===FRI===SAT===" << endl;
fout << "===SUN===MON===TUE===WED===THU===FRI===SAT===" << endl;
for (i = 0; i < dayrem; i++)
{
cout << setw(6) << setfill(' ') << "";
fout << setw(6) << setfill(' ') << "";
}
// Calculate the first day to input in the month
int count = dayrem % 7;
for (i = 0; i < day[monthdays - 1]; i++)
{
cout << setw(6) << setfill(' ') << i + 1;
fout << setw(6) << setfill(' ') << i + 1;
// changeline in each SAT
if (count >= 6)
{
cout << endl;
fout << endl;
count = 0;
}
else
{
count++;
}
}
cout << endl;
fout << endl;
fout.close();
system("pause");
return 0;
}// end of main function

Explanation / Answer

i fixed the bug for the leap year calculation but what is it u want do with the enum i.e (do u want the user to enter the name of the month then translate this to the enum and then do the calculation with the enum) if this is what u want do it is an easy thing u can make a switch statement for this and then assign the monthdays to the number specified bu the enum variable hope this helped u :O if u need anything just write a comment #include #include #include using namespace std; enum monthdays {JAN=31,FEB=28,MAR=31,APR=30,MAY,JUN=30,JUL,AUG=31,SEP=30,OCT,NOV=30,DEC}; int main(void) { // Design Method: // 1. There are 365 days in a year whcih means 52 weeks and 1 extra day Jan 1st Year 1 is Monday so Jan 1st Years 2 should be Tuesday // so we need to find out how many leap year will be in the calendar from year 1. // 2. Then we can use the method to calculate what day is in the firstday of each month. // 3. There is leap year after each 4 years, there is no leap year when face every 100 years, and there is a leap year when faced 400 years int i; int remainder; // Calculate the left over of days of the first month,it means to calculate what day it is in first month int year; // Calculate year int monthdays; // Calculate month // Define how many day in each month int day[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int dayrem; // discover the leftover in each Jan ifstream fin; ofstream fout; fout.open("cal.txt"); cout > year; cout > monthdays; cout