Calendar help

Hey everyone, new around here and I could use some help. I know you guys don't do peoples homework for them and thats fine but can anyone tell me if there's a function that would help me make a 3x4 calendar? I already have all the code that writes the calendar, i just don't know how to move april next to january, any ideas? Thanks everyone
How do you implement your calender? Is it pictures, characters what?

I didn't catch the general idea of what exactly you want to do so I can't really help you yet. So either you explain better or wait for someone else to understand better.
"move april next to january"
Huh? What kind of calendar are you doing?

EDIT:
Ooh, I get what you mean now. The guy below me has your idea. Though I always recommend 1D arrays over 2D.
Last edited on
i think you're gonna need a 3x4 array. http://www.cplusplus.com/doc/tutorial/arrays/
Sorry, i guess I can just post the code and you can see for yourselves. It's a really basic text calendar.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void printmonth(const int month, const int startday, const bool leap);
void printyear(const int year);
int dayofweek(const int day, const int month, const int year);


int main(void)
{
	int year;
	cout << "Enter a year after 1582 to be printed" << endl;
	cin >> year;
	cout << year << endl;
	printyear(year);
}

void printyear(const int year)
	{
		bool leapyear = false;
		if(year % 4 == 0)
		{
			if(year % 100 !=0)
			leapyear = true;
		}

		int mon = 1;
		for(mon = 1;mon < 13; mon++)
		printmonth(mon,dayofweek(1,mon,year),leapyear);
	}


//Finds what day of the week the year starts on
int dayofweek(const int day, const int month, const int year)
	{
		int a,y,m;
		a=(14-month)/12;
		y=year-a;
		m= month+12*a-2;
		return (day+y+y/4-y/100 + y/400 + (31*m/12))%7;
	}


void printmonth(const int month, const int startday, const bool leap)
{
	//Makes the arrays for the days of the week, the months, the days in each in month, and changes the days in Feb to 29 if leap is true.
	string Days[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
	string Months[13] = {"  ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
	int DaysinMonth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
	//Checks to see if it is a leap year and changes the days in February accordingly.
	if(leap)
		DaysinMonth[2] = 29;
	
	// Finds the length of the name of the month,divides it by 2, and adds that length + 14 spaces to the beginning, centering it.
	string str = Months[month];
	int len = str.length();
	cout << setw((len/2)+14) << Months[month] << endl;
	cout << "  Sun Mon Tue Wed Thu Fri Sat" << endl;
	
	// Adds four spaces for each day before startday
	int i = 1;
	int count = 0;
	for(count = 0; count < startday ; count++)
	{
		cout << "    ";
	}
	// Counts through the days of the month.
	for(i=1;i<=DaysinMonth[month];i++)

	{
		// Outputs each days numerical value, checks to see if it is the end of the week, and goes to the next day
		cout << setw(4) << i;
		if((startday+i) % 7 == 0)
			cout << endl;
	
		
	}
	
	cout << endl;

}
It prints off the months of a given year, one on top of the other, but i need it to print in a 3x4 view. I'm not sure how to put these in an array after theyve been printed, would I need to do it seperately from the for loop that prints the months?
Topic archived. No new replies allowed.