>asking how to write a calender in c++ using for loop
No problem:

int main()
{
  for ( int i = 1; i <= 12; i++ )
    print_calendar ( i, 2004 );
}

Of course, the print_calendar function is slightly more complicated. ;) Here's a quick stab at it:

void print_calendar ( int month, int year )
{
  int i;
  char month_name[20];
  struct tm date;

  date.tm_mday = 1;
  date.tm_mon = month - 1;
  date.tm_year = year - 1900;

  if ( mktime ( &date ) == -1 )
    return;

  strftime ( month_name, 20, "%B", &date );

  cout<< month_name <<'\n';
  cout<<"\nSun Mon Tue Wed Thu Fri Sat\n";

  for ( i = 0; i < date.tm_wday; i++ )
    cout<<"    ";

  do {
    cout<< left << setw ( 4 ) << date.tm_mday;

    if ( ++i % 7 == 0 )
      cout<<'\n';

    ++date.tm_mday;
    mktime ( &date );
  } while ( date.tm_mday != 1 );

  cout<<endl;
}

thanks....also what about a logbook i.e a calendar and at the same time they is some entries e.g a candy shop sales for each month for a particular year.

thanks....also what about a logbook i.e a calendar and at the same time they is some entries e.g a candy shop sales for each month for a particular year.

If you're doing a homework assignment, please post some code of your own, and we'll help you debug it. It's not our job in the forums here to do your homework for you.

>nway its not ma homework but a challenge i read from a ma data structures bk.
There's no difference. It's work given to you because you don't know how to do it already. It's not work given to us because we don't care about your book or your class or whatever, and we already know how to do it. The point is that if you don't do your own work, you won't learn squat.

This article has been dead for over six months. Start a new discussion instead.