All pastes #2086400 Raw Edit

Miscellany

public cpp v1 · immutable
#2086400 ·published 2011-10-03 08:51 UTC
rendered paste body
/*Tasks:Check what month it is.Check if it is a sunday. (if yes, sunday++)Check how many days are in this month.if it is february, check if it's a leap year.Move days so that it is the first again. repeat*/#include <iostream>using namespace std;// Declare Functionsbool CheckForSunday(int&);void AdvanceOneMonth(int&, int&, int&);void GoForJoe();int main(){	GoForJoe();		return 0;}void GoForJoe(){	int year = 1900;	int month = 1;	int sundays = 0, mo = 0, tu = 0, we = 0, th = 0, fr = 0, sa = 0;	int day = 1;		int d1 = day + 1;	int d2 = d1 + 1;	int d3 = d2 + 1;	int d4 = d3 + 1;	int d5 = d4 + 1;	int d6 = d5 + 1;		while (year < 2001)	{		if(CheckForSunday(day) && (year > 1900))			sundays++;		if(CheckForSunday(d1) && (year > 1900))			mo++;		if(CheckForSunday(d2) && (year > 1900))			tu++;		if(CheckForSunday(d3) && (year > 1900))			we++;		if(CheckForSunday(d4) && (year > 1900))			th++;		if(CheckForSunday(d5) && (year > 1900))			fr++;		if(CheckForSunday(d6) && (year > 1900))			sa++;		AdvanceOneMonth(day, month, year);	}	//	cout << endl << endl << "The answer is: " << sundays;	cout<< "Results:" << endl		<< "Mondays: " << mo << endl		<< "Tuesdays: " << tu << endl		<< "Wednesdays: " << we << endl		<< "Thursdays: " << th << endl		<< "Fridays: " << fr << endl		<< "Saturdays: " << sa << endl		<< "Sundays: " << sundays << endl;		}bool CheckForSunday(int& day){	if ((day == 0) || (day == 7) || (day % 7 == 0))	{		day = 0;//		cout << "It is sunday" << endl;		return true;	}	return false;	}void AdvanceOneMonth(int& day, int& month, int& year){	int days;		switch (month)	{		case 1:		case 3:		case 5:		case 7:		case 8:		case 10:		case 12:		{			days = 31;			break;		}		case 2:		{			if (year % 4 == 0)				days = 29;			else				days = 28;			break;		}		case 4:		case 6:		case 9:		case 11:		{				days = 30;			break;		}		case 13:		{			days = 31;			month = 1;			year++;		}	}		//	cout<< "Month: " << month << " of year " << year << " had " << days << " days." << endl//		<< "It started on day " << day;		//	days = days % 7;		day+= days;		while (day > 7)	{		day-= 7;	}	//	cout<< " and ends on day " << day << "." << endl;		month++;		//	cout << "AdvanceOneMonth,month: " << month << " Year: " << year;}