pass by reference college assignment

Hello.
I've searched your archives and found a similar question to mine and although I found your replies useful I am now stuck.
I am doing a project call NEWDAY using a pass by reference where I have to:
Write a function named NEWDAY using 3 parameters for month, day and year. ND has to increment the date represented by month,day and year.
Also have to write a main program which inputs a date (m,d,y) from keyboard and calls the NEWDAY in a loop in order to display the next 10 dates following input date. Main prog. handles all input/output.
This is what I have so far but it's not right and I am stuck as to how to proceed:
This is due tomorrow and I've worked many, many hours on this and I am just lost. I'm not asking anyone to fix this, just point me in the right direction, pretty please? Thank you so much.

#include <iostream>
using namespace std;
void NEWDAY (int&, int&, int&);
int main ()

{

int day=1, month=1, year, n;
cout<<"Enter a month (1-12): ";
cin>>month;
cout<<"Enter a day (1-31): ";
cin>>day;
cout<<"Enter year (yyyy): ";
cin>>year;
cout<<"The next ten days are: " <<endl;
for (n=0; n<=10; n++)
{
NEWDAY(month, day, year);
cout<<month <<"/" <<day <<"/" <<year <<endl;
}
system ("pause");
return 0;
}
void NEWDAY (int& d, int&m, int&y)
{

d++;
if ((m==4)||(m==6)||(m==9)||(m==11))

if(d>30);
{
d=1;
cout<<endl;
m++;

}
if (m==2)
{
if (d>28);
d=1;

m++;
}

if (m>12);
{m=1;
y++;
}







}
 
NEWDAY(month, day, year);  // note the order of the params 


 
void NEWDAY (int& d, int&m, int&y)  // note again 
Okay, fixed that, thank you!

When I run this using 12/31/2009 it gives me 1/1/2010...1/1/2011 etc. So obviously I do not need the y++ because it is incrementing years and not days.

Also note extraneous semicolons:

1
2
3
if(d>30);
if (d>28);
if (m>12);



I finally got it working, now, any pointers on how to incorporate leap year into this? Because I really have no idea where to put the code.

here is the program as I have it now:
(and once again thank you so much for your time)

#include <iostream>
void NEWDAY(int&, int&, int&); //function prototype
using namespace std;
int main ()
{

int month,day,year,n;
cout << "Enter a month(1-12): ";
cin >> month;
cout << "Enter a day(1-31): ";
cin >> day;
cout<< "Now enter a year(yyyy): ";
cin >> year;
cout << endl;

cout<< " The next ten days are: \n";
cout<<endl;
for (n=1;n<=10;n++)
{
NEWDAY(month,day,year);
cout <<month<<"/"<<day<<"/"<<year<<endl;
}
system ("pause");
return 0;
}
void NEWDAY (int& m, int& d, int& y) //function header
{
d++;
if ((m==4)||(m==6)||(m==9)||(m==11))
if (d>30)
{
d=1;
m++ ;
}
{
}
if ((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10))
if (d>31)
{
d=1;
m++;
}
if (m == 2)
if ( d > 28)
{
d=1;
m++;
}
if(m == 12)
if (d > 31)
{
y++;
d=1;
m=1;
{
}

}
}
Apologies, but could you please use code tags?

http://www.cplusplus.com/articles/firedraco1/
I'm sorry, I have no idea how I would even use code tags for this program. I am terribly programming illiterate and after taking this class I will leave it to those that truly understand it. :)
If my program is a jumbled mess I apologize and I understand that it will be impossible to help me. Please forgive my ignorance.
???

[code]/* stuff */[/code]
becomes
/* stuff */
I understand /* stuff */
becomes
/* stuff */
(I did go and read the article)
But, my ignorance is that I do not know what you want me to [code]. What parts of the program? Thanks again for your patience and assistance.
No. He means put the code you have there, inside the [code] tags

EDIT: I haven't looked at your code because it is not within [code]tags but in answer to your leap question just do 'year % 4. If it returns 0 it is a leap year.
Last edited on
Okay, now that I feel REALLY dumb...is this what you meant?
if not I'm going to just crawl in a hole. *laughs* thanks!

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>    

void NEWDAY(int&, int&, int&); //function prototype
using namespace std;
int main ()
{
   
    int month,day,year,n;
    cout << "Enter a month(1-12): ";
      cin >> month;
    cout << "Enter a day(1-31): ";
      cin >> day;
    cout<< "Now enter a year(yyyy): ";
      cin >> year;
    cout << endl;
             
    cout<< "The next ten days are: \n";  
    cout<<endl;
        for (n=1;n<=10;n++)
{
      NEWDAY(month,day,year);
      cout <<month<<"/"<<day<<"/"<<year<<endl;
}
       system ("pause");
       return 0;
}
void NEWDAY (int& m, int& d, int& y) //function header
{
       d++;
         if ((m==4)||(m==6)||(m==9)||(m==11))
         if (d>30)
{ 
                d=1;
       m++ ;
}                                                
{
}
         if ((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10))
         if (d>31)
{  
        d=1;
        m++;
}
          if (m == 2)
          if ( d > 28)
{
        d=1;
        m++;
}
          if(m == 12)
          if (d > 31)
{
        y++;
        d=1;
        m=1;
{
}
       
}
}
Yes, that's it. The indentation is weird though; why are all of the curly braces outdented as much as possible?

And I would try running it through a debugger to see exactly what the variables are at certain points. You will probably be able to figure out what the error is using only that.
Topic archived. No new replies allowed.