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

Can anyone help me change some code below... It require to enter 0 as Sunday and

ID: 3590026 • Letter: C

Question

Can anyone help me change some code below... It require to enter 0 as Sunday and 1 as Monday........... 6 as Saturday....

In addition, my program below does not continue the date at the end of the month to the start day of the month

#include<iostream>

#include<cmath>

using namespace std;

int main ()

{

int year, start_day, days=0, month(1);

//User enter the year

cout << "Enter a year. ";  

cin >> year;

//User enter the first day of the year

cout << "Enter the first day of the year (Sunday is 0, Monday is 1.....,Saturday is 6): ";

cin >> start_day;

//Loop to display 12 month

while (month <= 12)

{

//Display days in a month... And predict if it's a leap year or not

switch (month)

{

case 1:

cout << " " << "January " << year;

days = 31;

break;

case 2:

cout << " " << "February " << year << endl;

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

{

days = 29;

}

else

{

days = 28;

}

break;

case 3:

cout << " " << "March " << year;

days = 31;

break;

case 4:

cout << " " << "April " << year;

days = 30;

break;

case 5:

cout << " " << "May " << year;

days = 31;

break;

case 6:

cout << " " << "June " << year;

days = 30;

break;

case 7:

cout << " " << "July " << year;

days = 31;

break;

case 8:

cout << " " << "August " << year;

days = 31;

break;

case 9:

cout << " " << "September " << year;

days = 30;

break;

case 10:

cout << " " << "October " << year;

days = 31;

break;

case 11:

cout << " " << "November " << year;

days = 30;

break;

case 12:

cout << " " << "December " << year;

days = 31;

break;

default:

;

}

//Display weekday on top of the calendar

cout << endl << ("---------------------------------------------------");

cout << endl << "Sun Mon Tue Wed Thr Fri Sat ";

//Adjust the spot of the calendar

for (int i = 0; i < start_day; i++)

{

cout << " ";

}

//Display day from 1-31

for (int i = 1; i <= days; i++)

{

if (((i + start_day) % 7 == 0))

cout << endl;

cout << i << " ";

}

cout << endl << endl;

start_day= (start_day + days) %7;

month ++;

}

return 0;

}

Explanation / Answer

Please find the updated code as you requested below.

#include<iostream>
#include<cmath>
using namespace std;

int main ()
{
int year, start_day, days=0, month(1);
//User enter the year
cout << "Enter a year. ";
cin >> year;
//User enter the first day of the year
cout << "Enter the first day of the year (Sunday is 0, Monday is 1.....,Saturday is 6): ";
cin >> start_day;
//Loop to display 12 month
while (month <= 12)
{
//Display days in a month... And predict if it's a leap year or not
switch (month)
{
case 1:
cout << " " << "January " << year;
days = 31;
break;
case 2:
cout << " " << "February " << year << endl;
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
{
days = 29;
}
else
{
days = 28;
}
break;
case 3:
cout << " " << "March " << year;
days = 31;
break;
case 4:
cout << " " << "April " << year;
days = 30;
break;
case 5:
cout << " " << "May " << year;
days = 31;
break;
case 6:
cout << " " << "June " << year;
days = 30;
break;
case 7:
cout << " " << "July " << year;
days = 31;
break;
case 8:
cout << " " << "August " << year;
days = 31;
break;
case 9:
cout << " " << "September " << year;
days = 30;
break;
case 10:
cout << " " << "October " << year;
days = 31;
break;
case 11:
cout << " " << "November " << year;
days = 30;
break;
case 12:
cout << " " << "December " << year;
days = 31;
break;
default:
;
}
//Display weekday on top of the calendar
cout << endl << ("---------------------------------------------------");
cout << endl << "Sun Mon Tue Wed Thr Fri Sat ";
//Adjust the spot of the calendar
for (int i = 0; i < start_day; i++)
{
cout << " ";
}
// Created Temp Variable to hold start day
int temp_day = start_day;
//Display day from 1-31
for (int i = 1; i <= days; i++)
{
if(temp_day!=0) // skip the additional end line if temp date is zero
if (((temp_day) % 7 == 0)) // utilized temp date instead
cout << endl;
cout << i << " ";
temp_day = temp_day + 1; // incremented temp date
}
cout << endl << endl;
start_day= (start_day + days) %7;
month ++;

}


return 0;
}

Kindly let me know in case you need more details.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote