New student needs direction

Good Day, I am a new student with an issue, I need some direction on this lab assignment. I can't seem to get the hang of functions to work in this program can anyone offer any direction here. Much Thanks in advance.





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

//funtion prototype
void dayNumber(month,day, year);
void leap(year);

int main()
{
int (month, day, year);
char c;
bool (leap) = false;

{
cout << "Enter a date in the form MM-DD-YYYY: ";
cin >> month >> c >> day >> c >> year ;

system ("cls");

daynumber(month, day, year);

leap(year);




// Then add the day number to that sum
int dayNum = sum + day;

cout << " The day number for " << month << "/" << day << "/" << year << " is " << dayNum << endl;

system ("pause");
return 0;
/* end main*/

}
void leap(year)
{
int numberOfDaysInMonth = 0;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numberOfDaysInMonth = 31;
break;

case 4:
case 6:
case 9:
case 11:
numberOfDaysInMonth = 30;
break;

case 2:
if (((year % 4 == 0) && (year % 100 != 0))
|| (year % 400 == 0))
numberOfDaysInMonth = 29;
else
numberOfDaysInMonth = 28;
}

if (day < 1 || day > numberOfDaysInMonth)
leap = false;
else
leap = true;
} //end leap
// compute the day number
// Add up the number of days in all earlier months
// of this year

void dayNumber(month,day, year)
int sum = 0;
for (int m = 1; m < month; ++m)
{
int monthLength = 0;
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
monthLength = 31;
break;

case 4:
case 6:
case 9:
case 11:
monthLength = 30;
break;

case 2:
if (((year % 4 == 0) && (year % 100 != 0))
|| (year % 400 == 0))
monthLength = 29;
else
monthLength = 28;
you need to add the code for the function under the main program code. you need to ceep the file declarations on top of the main section. also need to ad type in your declarations see below
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <iomanip>
using namespace std;

//funtion prototype
void dayNumber(int month,int day, int year);
void leap(int year);

int main()
{
int (month, day, year);
char c;
bool (leap) = false;

{
cout << "Enter a date in the form MM-DD-YYYY: ";
cin >> month >> c >> day >> c >> year ;

system ("cls");

daynumber(month, day, year);

leap(year);




// Then add the day number to that sum
int dayNum = sum + day;

cout << " The day number for " << month << "/" << day << "/" << year << " is " << dayNum << endl;

system ("pause");
return 0;
/* end main*/

}
void leap(year)
{
int numberOfDaysInMonth = 0;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numberOfDaysInMonth = 31;
break;

case 4:
case 6:
case 9:
case 11:
numberOfDaysInMonth = 30;
break;

case 2:
if (((year % 4 == 0) && (year % 100 != 0))
|| (year % 400 == 0))
numberOfDaysInMonth = 29;
else
numberOfDaysInMonth = 28;
}

if (day < 1 || day > numberOfDaysInMonth)
leap = false;
else
leap = true;
} //end leap
// compute the day number
// Add up the number of days in all earlier months
// of this year

void dayNumber(month,day, year)
int sum = 0;
for (int m = 1; m < month; ++m)
{
int monthLength = 0;
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
monthLength = 31;
break;

case 4:
case 6:
case 9:
case 11:
monthLength = 30;
break;

case 2:
if (((year % 4 == 0) && (year % 100 != 0))
|| (year % 400 == 0))
monthLength = 29;
else
monthLength = 28;

void dayNumber(int month,int day, int year);
{
   do something
   return something
}
void leap(year);
{
do something
return something
}
I have to say I am really lost here, all of this is out of my standard. I could use some more direction on this reply. or a diferent approach to the solution. I am trying to understand but very new here.
in you code that you posted you had the functions you wanted to call declared in the right spot which they have to be. but you need to have the code that actually does what ever you wish to do defined at the end of your program. also in the declaration and define part of the functions you need to tell the compiler the varible name but also what type it is. example:
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
#include <iostream>
#include <iomanip>
using namespace std;

void daynumber(int month, int day, int year); // this declares the function
void leap(int year);
/* this declares the functions you are going to use in the program notice that the varible have what type they are */

int main()
{

declare varibles
do somethings 
daynumber(month,day,year); // this calls funtion day number do not need type by correct type
do something
leap(year);  // This calls the function
print out something

return 0;
}

/* here is where the function is defined */

void daynumber(int m, int d, int y)
/* Notice i change the name of the variables but not the type. you can leave varible names the same if you want but you can change them just not the type they are both declaration and definition must have the same types. */
do somethings
return;
}

void leap(int y)  // This defines the function
{
check if year is leap year
return;
}


I think you might want to change your functions to return something other than void as you need to return integers from your functions but i could be wrong on that point. Just remember when using function first you must declare them before the main section of your program and then define them below the main section of your code.

You must have both what type the each variable passed to the function is and the variables name
in where you declare and where you define the function.
example: int a(int fish, float animal);
calling the function you only need the variables name.

See the following for more help

http://www.cplusplus.com/doc/tutorial/functions/

http://www.cplusplus.com/doc/tutorial/functions2/
Topic archived. No new replies allowed.