User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,079 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,018 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1364 | Replies: 5 | Solved
Reply
Join Date: Oct 2006
Posts: 35
Reputation: JS1988 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
JS1988 JS1988 is offline Offline
Light Poster

quick question

  #1  
Nov 3rd, 2006
Quick question, what do i want to put in the while of my do while statement in myprintitle function so that will loop around with the main part as well.

 
include<iostream>
#include<iomanip>
using namespace std;
int startDay(int , int );
int calcjan1(int, int );
void printMonth (int , int );
int days(int ,int , int );
int daysinmonth(int , int );
void printtitle(int , int );
int monthnum;
int main()
{
int jan=0;
char y;
char again;
int year=0; 
int month = 1;
int monthnum = 1;
do
{
    cout<<"Enter a year for a calendar you would like to view:";
    cin>>year; 
   int startDay = calcjan1(year, jan); 
   for(month = 1;month<= 12; month++,monthnum++)
    {
        int days = daysinmonth( month,year);
         
         printtitle(monthnum,year);
         printMonth(startDay,days);
         startDay = (startDay + days)%7;
     }
     cout<<"Would you like to enter another year?: Hit y to continue";
     cin>>again;
system("Pause");
}while (again=='y'); 
 
return 0;
}
//====================calcjan1===================
//calculates the first day of Jan. for year entered
int calcjan1(int year, int jan)
{
     jan = ((year-1)*365+((year-1)/4)-((year-1)/100)+(((year-1)/400))+1)%7;
    return jan; 
}//calcjan1
//===============printMonth==============
void printMonth (int startDay, int days)
{
     cout<<"Sun Mon Tue Wed Thu Fri Sat\n";
     cout<<"--- --- --- --- --- --- ---\n";
    for(int skipDay = 0;skipDay < startDay; skipDay++)
          cout<<"    ";
    int weekDay = startDay;
    for (int dayCount =1; dayCount <=days; dayCount++)
     {
         if (weekDay>6)
          {
               cout<<endl;
               weekDay =1; 
          }
         else 
               weekDay++;
          cout<<setw(3) <<dayCount<<" ";
      } 
     cout<<"\n--- --- --- --- --- --- ---\n";
   
    return;
} 
//===================printtitle==================
//print the month name & year
void printtitle(int monthnum,int year)
{
  do
  {
    int month= monthnum;
    switch(monthnum)
     {
         case 1: cout<<"January"<<setw(20)<<year<<endl;
              break;
         case 2: cout<<"February"<<setw(19)<<year<<endl;
              break;
         case 3: cout<<"March"<<setw(22)<<year<<endl;
              break;
         case 4: cout<<"April"<<setw(22)<<year<<endl;
              break;
         case 5: cout<<"May"<<setw(24)<<year<<endl;
              break;
         case 6: cout<<"June"<<setw(23)<<year<<endl;
              break;
         case 7: cout<<"July"<<setw(23)<<year<<endl;
              break;
         case 8: cout<<"August"<<setw(21)<<year<<endl;
              break;
         case 9: cout<<"September"<<setw(18)<<year<<endl;
              break;
         case 10: cout<<"October"<<setw(20)<<year<<endl;
              break;
         case 11: cout<<"November"<<setw(19)<<year<<endl;
              break;
         case 12: cout<<"December"<<setw(19)<<year<<endl;
              break;
          } 
     }while();   <RIGHT HERE
         
         return;
}//printtitle
//========================daysinmonth===================
//checks for leap year
int daysinmonth(int month,int year)
{ 
    switch(month)
     { 
         case 4:case 6:case 9:case 11: return 30;
              break;
         case 1:case 3:case 5:case 7:case 8:case 10:case 12: return 31;
              break;
         case 2: if((!(year % 4) && (year % 100) || !(year % 400)))
              return 28;
         else 
              return 29;
         break;
       }
     return 0;
}//daysinmonth
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,562
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 860
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: quick question

  #2  
Nov 3rd, 2006
what is the purpose of that do loop? Why not just remove it ? And you don't need that switch statement if you put the month names in an array of strings.
char *months[] = { "", "January","February", ... "December"}
cout<< months[monthnum] <<setw(20)<<year<<endl;
Last edited by Ancient Dragon : Nov 3rd, 2006 at 10:29 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Oct 2006
Posts: 35
Reputation: JS1988 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
JS1988 JS1988 is offline Offline
Light Poster

Re: quick question

  #3  
Nov 3rd, 2006
I didnt ask you to write this program, I wrote it.And i thought i used the code tag because i highlighted the text and hit the code text button, which is what i was told to do. the loop is needed so it will print all those titles again if someone wanted to enter another year again after the first time. otherwise it just prints the dates. I was just wondering if anybody new what could be used to loop printtitle with the main
Last edited by JS1988 : Nov 3rd, 2006 at 10:33 pm.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,562
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 860
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: quick question

  #4  
Nov 3rd, 2006
Originally Posted by JS1988 View Post
I didnt ask you to write this program, I wrote it.
Yes you did and no one is trying to do it for you. I was attempting to make some constructive criticism to show better way of coding something. If you plan to write computer programs you might as well get used to that because you will encounter criticisms your entire career. Its called "peer review" and required by most companies that you will work for. you might as well get over being so defensive about other more experience programmers evaluating your code.

Originally Posted by JS1988 View Post
.And i thought i used the code tag because i highlighted the text and hit the code text button, which is what i was told to do.
I didn't say anything about code tags -- what you saw is in my signture and appears in every post I make. Yes you did use code tags correctly.


Originally Posted by JS1988 View Post
.the loop is needed so it will print all those titles again if someone wanted to enter another year again after the first time. otherwise it just prints the dates. I was just wondering if anybody new what could be used to loop printtitle with the main


you don't have to do anything. When printtitle() function returns the loop in main will take care of everything. The do loop in printtitle() is not needed.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Oct 2006
Posts: 35
Reputation: JS1988 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
JS1988 JS1988 is offline Offline
Light Poster

Re: quick question

  #5  
Nov 3rd, 2006
I was only being defensive because I didnt realize that was your signature. It said
A Ask all the questions you need to, but please do not ask us to write your programs for you.
and i didnt realize that was your signature. And if you run the program once and then tell it to go again it wont print those titles like it does the first time.
Reply With Quote  
Join Date: Oct 2006
Posts: 35
Reputation: JS1988 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
JS1988 JS1988 is offline Offline
Light Poster

Re: quick question

  #6  
Nov 3rd, 2006
never mind i figured it out i needed to put an if statement after i call the printtitle to reset monthnum back to 0 so it will go through again.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC