Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,557 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,909 people online right now. Registration is fast and FREE... Join Now!




C++ Calander Program .......I'm sooooo close, I need your help.

 
Reply to this topicStart new topic

C++ Calander Program .......I'm sooooo close, I need your help., My program outputs a 12 month calendar for any year, but it dosn't

Bananna
7 May, 2008 - 01:10 PM
Post #1

New D.I.C Head
*

Joined: 7 May, 2008
Posts: 5

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
*/

This post has been edited by Bananna: 7 May, 2008 - 02:28 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:21PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month