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

I have a program written out, the only thing I forgot to do was validate the yea

ID: 3626201 • Letter: I

Question

I have a program written out, the only thing I forgot to do was validate the year and the days inputted by user. For example, the year has to be within the range of 1582-2011 and if user enters something lower or higher than given range, must give an error message and let user re enter the year again. Same thing when entering the day of the week of january 1st 0 being for sunday, 1 for mondaya nd so on.. 6 for saturday. If user enters something higher than 6 and lower than 0, must give error message and let user input the day of the week again. Here is my code:


#include <iostream>
#include <iomanip>
using namespace std;
//declaring the functions used throughout the program
void printMonths(int numofDays, int &daytoStart);
void getNumofDays(int months, int &numofDays,int years);
bool isLeapYear(int years);
void getData(int &years, int &daytoStart);
void printTitles(int months);
//main function
int main()

{
//declaring variables
int daytoStart,years,months,numofDays;


getData(years, daytoStart);
//loops out the twelve months in a year
for(months=1;months<13;months++)
{
printTitles(months);
getNumofDays(months, numofDays,years);
printMonths( numofDays, daytoStart);
cout<<" ";

}

cout<<" ";
system("pause");

}
//end of main function
//function that prints out the months and days of the week
void printTitles(int months)

{
switch(months)

{

case 1 : cout << " *~*~*JANUARY*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 2 : cout << " *~*~*FEBRUARY*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 3 : cout << " *~*~*MARCH*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 4 : cout << " *~*~*APRIL*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 5 : cout << " *~*~*MAY*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 6 : cout << " *~*~*JUNE*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 7 : cout << " *~*~*JULY*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 8 : cout << " *~*~*AUGUST*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 9 : cout << " *~*~*SEPTEMBER*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 10 : cout << " *~*~*OCTOBER*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 11 : cout << " *~*~*NOVEMBER*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;

case 12 : cout << " *~*~*DECEMBER*~*~*" << endl;
cout << " S M T W Th F S" << endl;
cout << "----------------------" << endl;
break;
}
}
//end of function void
//function that lets user enter the year and the day of the week
//in which January 1st starts on

void getData(int &years, int &daytoStart)
{

I believe here is where a loop needs to go; I've tried it with bool, but apparently having trouble

 

{


cout <<

"Please enter the year for a calendar:" << endl;


cin >> years;


        cout <<

"Please enter the day of the week for January 1:" << endl;


cout <<

"Enter 0 for Sunday, 1 for Monday, etc" << endl;


cin >> daytoStart;


 


cout<<

" *~*~*~*~*Calendar of Year*~*~*~*~* "<


cout<<

" *****"<"*****"<



}


//end of void function


//This function helps in determining the leap year


bool

 

isLeapYear(int years)


 


{


 

if (years % 400 == 0)


{


 

return true;


}


 

if (years % 100 == 0)


{


 

return false;


}


 

return years % 4 == 0;


}


//end of bool function


//This function determines which month is leap year and how many days it has


void

 

getNumofDays(int months, int &numofDays,int years)


{


 

switch (months)


 


{


 

case 1 :


 

case 3 :


 

case 5 :


 

case 7 :


 

case 8 :


 

case 10:


 

case 12: numofDays = 31;


 

break;


 

case 4 :


 

case 6 :


 

case 9 :


 

case 11: numofDays = 30;


 

break;


 

case 2 :


 

if(isLeapYear(years))


numofDays = 29;


 

else


numofDays=28;


 

break;


}


}


//end of void function


//This functions helps in printing out the month with the correct days in calendar


void

 

printMonths(int numofDays, int &daytoStart)


{


 

//loop that helps in determining where the day one begins; first 7 days of week 0 to 6


 

int dayCount=1;


 

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


{


 

if(i>=daytoStart)


cout<


 

else


cout<

" ";


}


cout<


 

while(dayCount<=numofDays)


{


 

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


{


 

if(dayCount<=numofDays)


cout<


 

else


{


 

break;


}


daytoStart=i+1;


}


cout<


}


}


//end of the function

Explanation / Answer

please rate - thanks

the CRAMSTER editor destroyed your code, so I wasn't able to check it

void getData(int &years, int &daytoStart)
{
//I believe here is where a loop needs to go; I've tried it with bool, but apparently having trouble

cout <<"Please enter the year for a calendar:" << endl;
cin >> years;
while(year<1582||year>2011)
    {cout<<"must be between 1582 and 2011 ";
    cout <<"Please enter the year for a calendar:" << endl;
    cin >> years;
    }

cout <<"Please enter the day of the week for January 1:" << endl;
cout <<"Enter 0 for Sunday, 1 for Monday, etc" << endl;
cin >> daytoStart;
while(daytoStart<0||daytoStart>6)
    {cout<<"must be between 0 for Sunday and 6 for Saturday ";
    cout <<"Please enter the day of the week for January 1:" << endl;
    cout <<"Enter 0 for Sunday, 1 for Monday, etc" << endl;
    cin >> daytoStart;
    }
cout<<" *~*~*~*~*Calendar of Year*~*~*~*~* "<
cout<<" *****"<"*****"<
}
//end of void function