C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 7th, 2008, 05:21 PM
Bananna Bananna is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 1 Bananna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 46 sec
Reputation Power: 0
Calendar Help...Almost finished!!!

January starts in the right location but Feb, Mar, Apr, and every other month starts in the same spot as January, I'm sooo close please help me fix this last problem......

CODE

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

//function prototypes

int First_Day_Of_Month(int y, int m);
int Number_Days_Of_Month(int y, int m);
bool IsLeapYear(int y);
void Print_Version();
void Print_Head(int y);
void Print_Month(int y, int m);
void Print_Month_Head(int m);

void main ()
{
int year;
Print_Version();
cin>> year;
Print_Head(year);

for(int i=1; i<=12; i++)
{
Print_Month(year, i);
}
cout<<"\n\n\nGoodbye!\n";
}

//Some Functions

void Print_Version()
{
cout<<"Enter any Year After 1753 to output a very pretty calendar for that year!\n";
}
void Print_Head(int y)
{
cout<<"\n\n"<<setw(21)<<y<<endl;
}
void Print_Month(int year, int month)
{
int firstday, number_days;

Print_Month_Head(month);
firstday = First_Day_Of_Month(year,month);
number_days = Number_Days_Of_Month(year,month);
cout << " ";

for(int k=0; k<firstday; k++)
cout << " ";
for(int i = 1; i<=number_days; i++)
{
cout<<setw(5)<<i;
if((i + firstday)%7 == 0)
{
cout << endl;
cout << " ";
}
}
}
bool IsLeapYear(int year)
{
if(year%400 == 0)
{
return 1;
}
else if (year%4 == 0 && year%100 != 0)
{
return 1;
}
else
return 0;
}
int First_Day_Of_Month(int year, int month)
{
int firstday;

for(month = 1; month<13; month++)
{
if(month<3)
{
month=month + 12;
year=year-1;
}
firstday = (1 + (2 * month) + ((6 * (month + 1)) / 10) + year + (year / 4) -
(year / 100) + (year / 400) + 1) % 7;

}
return firstday;
}
int Number_Days_Of_Month(int year, int month)
{
int Leapyear;
Leapyear = IsLeapYear(year);
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
return 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
return 30;
}
else if (Leapyear == 1)
{
return 29;
}
else
{
return 28;
}
}
void Print_Month_Head(int month)
{
if(month==1)
{
cout<<" ==================================";
cout<<"\n January\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==2)
{
cout<<"\n\n ==================================";
cout<<"\n February\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==3)
{
cout<<"\n\n ==================================";
cout<<"\n March\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==4)
{
cout<<"\n\n ==================================";
cout<<"\n April\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==5)
{
cout<<"\n\n ==================================";
cout<<"\n May\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==6)
{
cout<<"\n\n ==================================";
cout<<"\n June\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==7)
{
cout<<"\n\n ==================================";
cout<<"\n July\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==8)
{
cout<<"\n\n ==================================";
cout<<"\n August\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==9)
{
cout<<"\n\n ==================================";
cout<<"\n September\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==10)
{
cout<<"\n\n ==================================";
cout<<"\n October\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==11)
{
cout<<"\n\n ==================================";
cout<<"\n November\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else
{
cout<<"\n\n ==================================";
cout<<"\n December\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
}


My output wont paste right here but you can see the problem, there is 5 days in the first week of every month....AAAARRRRGGGGHHHH!!!!!
/*Output

Enter any Year After 1753 to output a very pretty calendar for that year!
2008


2008
==================================
January

Sun Mon Tue Wed Thu Fri Sat
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

==================================
February

Sun Mon Tue Wed Thu Fri Sat
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

==================================
March

Sun Mon Tue Wed Thu Fri Sat
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

==================================
April

Sun Mon Tue Wed Thu Fri Sat
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

==================================
May

Sun Mon Tue Wed Thu Fri Sat
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

==================================
June

Sun Mon Tue Wed Thu Fri Sat
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

==================================
July

Sun Mon Tue Wed Thu Fri Sat
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

==================================
August

Sun Mon Tue Wed Thu Fri Sat
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

==================================
September

Sun Mon Tue Wed Thu Fri Sat
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

==================================
October

Sun Mon Tue Wed Thu Fri Sat
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

==================================
November

Sun Mon Tue Wed Thu Fri Sat
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

==================================
December

Sun Mon Tue Wed Thu Fri Sat
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


Goodbye!
Press any key to continue
*/

Reply With Quote
  #2  
Old May 8th, 2008, 01:41 AM
lokesh@nitw lokesh@nitw is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 lokesh@nitw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 42 sec
Reputation Power: 0
please send reply after reading this,reply is must



hi my name is lokesh
I saw your program ,you lost the logic to print the date in correct place you must write a loop to avail spaces and to print the date at the right place and you must check that the dates must not be printed after saturday after that you must send a value to next month which indicates the position of the first date to be printed .that's all...


can you try this short program which can print the calendar of any year right from year 1. if you had any doubt in this program you can ask me questions in this site or through Gtalk my id is lokesh755
....
Here is the program

PHP Code:
#include<iostream.h>
#include<conio.h>
int showmonth(int m,int y,int n);
int main()
{         
char x;
          
x='y';
          while(
x=='y')
          {
          
int n,y;
          
cout<<"Enter any year :- ";
          
cin>>y;
          
cout<<"\n\n\n\t\tCALENDAR OF THE YEAR  ";
          
cout<<y<<endl;
          
n=(y-1)*(365+0.25-0.01+0.0025);
          
n++;
          for(
int k=1;k<=12;k++)
          {
          
n=showmonth(k,y,n);
          }
          
cout<<"If you want to continue press 'y'\n Enter here:-  ";
          
cin>>x;
          }
          
getch();
          return 
0;
}
int showmonth(int m,int y,int n)
{
       
int d=1,s=1,k=31,p;
       switch(
m)
       {
 case 
:cout<<"\nJANUARY\n";
        
k=31;
        break;
 case 
:cout<<"\nFEBRUARY\n";
        if(((
y%4==0)&&(y%100!=0))||(y%400==0))
        
k=29;
        else
        
k=28;
        break;
 case 
3cout<<"\nMARCH\n";
        
k=31;
        break;
 case 
4cout<<"\nAPRIL\n";
        
k=30;
        break;
 case 
5:cout<<"\nMAY\n";
        
k=31;
        break;
 case 
6:cout<<"\nJUNE\n";
        
k=30;
        break;
 case 
7:cout<<"\nJULY\n";
        
k=31;
        break;
 case 
8:cout<<"\nAUGUST\n";
        
k=31;
        break;
 case 
9:cout<<"\nSEPTEMBER\n";
        
k=30;
        break;
 case 
10:cout<<"\nOCTOBER\n";
        
k=31;
        break;
 case 
11:cout<<"\nNOVEMBER\n";
        
k=30;
        break;
 case 
12:cout<<"\nDECEMBER\n";
        
k=31;
        break;      
}  
cout<<endl<<y<<endl;     
n=n%7;  
cout<<"\n-----------------------------------------------------\n";        
cout<<"SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\t\n";
cout<<"\n-----------------------------------------------------\n";
while(
s<=n)
{
        
cout<<"\t";
        
s++;
}
while((
n<7)&&(d<=k))
{
while((
n<7)&&(d<=k))
{
cout<<d<<"\t";
n++;
d++;
}
cout<<"\n";
p=n;
n=0;
}
cout<<"\n-----------------------------------------------------\n";
return(
p);


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Calendar Help...Almost finished!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway