GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Dec-2010, 12:36
centifnel centifnel is offline
New Member
 
Join Date: Dec 2010
Posts: 2
centifnel is on a distinguished road

How to make a calendar


the programe i want to create is the following:

the user enters the year and the number of day(ex. if you enter 2 the calendar will start from January and monday will have the number 2)
then the program displays all months starting with monday as the number you entered

the problem i have is that all my months start from monday with number 1.. can we fix this? i am new in c++ soo...
heres my code:

CPP / C++ / C Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	const int n =16;
	int day =1, month, year, last;

	    cout << "What year do you want the calendar for? ";
                 cin >> year;
	    cout << "What day the 1st of January fall ?";

	for (int month=1; month<=12; month++)
	{
	switch(month)

	{
	case 1:cout << setw(n+3) << "January";break;
	case 2:cout << setw(n+4) << "February";break;
	case 3:cout << setw(n+2) << "March";break;
	case 4:cout << setw(n+2) << "April";break;
	case 5:cout << setw(n+1) << "May";break;
	case 6:cout << setw(n+2) << "June";break;
	case 7:cout << setw(n+2) << "July";break;
	case 8:cout << setw(n+3) << "August";break;
	case 9:cout << setw(n+4) << "Semtember";break;
	case 10:cout << setw(n+3) << "Octomber";break;
	case 11:cout << setw(n+4) << "November";break;
	case 12:cout << setw(n+4) << "December";break;
	}
	switch (month)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12: last = 31;break;
	case 2: if (((year%4==0) && (year%100!=0))|| (year%400==0))
				last = 29;
			else
		                          last = 28;break;
	case 4:
	case 6:
	case 9:
	case 11: last = 30;break;
	}

	cout << "\n\n   M   T   W   T   F   S   S\n";
	cout << "   -------------------------\n";
	day = 1;
	
	while (day<=last)
	{
		cout << setw(4) << day;
		if (day%7==0) cout << endl;
		day++;
	}
	cout << "\n\n\n";
	}
	return 0;
}
Last edited by LuciWiz : 03-Dec-2010 at 15:06. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 03-Dec-2010, 12:57
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: how to make a calendar, pls help


Your description is inconsistent with the code you posted:
Code:
(ex. if you enter 2 the calendar will start from January and monday will have the number 2)
is not consistent with
Code:
cout << "What day the 1st of January fall (o for Sun, 1 for Mon, 2 for tue, etc)? ";
Maybe you could clarify. Then, post some example input and output for us to really see what the program is supposed to do.
  #3  
Old 03-Dec-2010, 13:04
centifnel centifnel is offline
New Member
 
Join Date: Dec 2010
Posts: 2
centifnel is on a distinguished road

Re: how to make a calendar, pls help


erhm i mean that the number you enter it will start your month with that number

if you enter 1, monday will start from one. if you enter 2 monday will start from number 2
  #4  
Old 03-Dec-2010, 15:32
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 969
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: how to make a calendar, pls help


I still don't know what your program is supposed to do and show as output.
Quote:
Originally Posted by fakepoo
...Then, post some example input and output for us to really see what the program is supposed to do.
  #5  
Old 12-Dec-2010, 23:46
Howard_L Howard_L is offline
Senior Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 1,004
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: How to make a calendar


Well you've got two problems to solve which are kinda related.
1- You need the have the user till you what day of the week January 1st is.
2- Your program will have to continue the weekdays correctly in each successive month.
Code:
January 2011 M T W T F S S 30 31 February 2011 M T W T F S S 1 2 3 4 5
but you already knew that didn't you
 
 

Recent GIDBlogPlanned Network Maintenance on 2013-05-29 by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use Calendar control 8.0 with MFC? hvtin .NET Forum 6 20-Aug-2004 02:28
Apache Make Fails beardo Apache Web Server Forum 6 09-Mar-2004 10:44
What are the best (server)options 2 make an Messenger with c++ client?! lj1979 C++ Forum 3 02-Sep-2003 09:14

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:01.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.