undefined reference error(Help)

I'm trying to find the total yearly rainfall it keeps giving me an undefined reference error.

[code]
#include<iostream>
#include<math.h>
#include<conio.h>



using namespace std;

float January(float);
float February(float);
float aggRain(float);

int main(){
int month_Rain;
int ave_daily;
int ave_month;
int year_Rain=0;
int highest_month;
int lowest_month;
int days;
int highest_year;
int lowest_year;
int Jan_rain=0;
int Feb_rain=0;
float rainfall;
int aggrain;
float month1;
float month2;
float total=0;




cout<<"Please enter the rainfall for january\n";
month_Rain = January(Jan_rain);
cout<<"the rainfall for this month is: ";
cout<<month_Rain<<endl;

cout<<"Please enter the rainfall for february\n";
month_Rain = February(Feb_rain);
cout<<"the rainfall for this month is: ";
cout<<month_Rain<<endl;

year_Rain = aggRain(total);
cout<<"The yearly rainfall is ";
cout<<year_Rain<<endl;

getch();

}

float January(float){
float Jan_rain;
int days =1;
float rainfall=0;
float aggrain =0;

while(days <= 31)
{ cout<<"\nPlease enter the rainfall for day " <<days<<": ";
cin>>rainfall;
Jan_rain += rainfall;

days++; }

return Jan_rain;


}

float February(float){
float Feb_rain=0;
int days =1;
float rainfall=0;
float aggrain =0;

while(days <= 28)
{ cout<<"\nPlease enter the rainfall for day " <<days<<": ";
cin>>rainfall;
Feb_rain += rainfall;

days++; }

return Feb_rain;

}

float aggRain(float Jan_rain, float Feb_rain){
float total=0;

total= January(Jan_rain)+ February(Feb_rain);

return total;

}


[/coode]
This is your code in readable format.
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
#include<iostream>
#include<math.h>
#include<conio.h>



using namespace std;

float January(float);
float February(float);
float aggRain(float);

int main()
{
    int month_Rain;
    int ave_daily;
    int ave_month;
    int year_Rain = 0;
    int highest_month;
    int lowest_month;
    int days;
    int highest_year;
    int lowest_year;
    int Jan_rain = 0;
    int Feb_rain = 0;
    float rainfall;
    int aggrain;
    float month1;
    float month2;
    float total = 0;




    cout << "Please enter the rainfall for januaryn";
    month_Rain = January(Jan_rain);
    cout << "the rainfall for this month is: ";
    cout << month_Rain << endl;

    cout << "Please enter the rainfall for februaryn";
    month_Rain = February(Feb_rain);
    cout << "the rainfall for this month is: ";
    cout << month_Rain << endl;

    year_Rain = aggRain(total);
    cout << "The yearly rainfall is ";
    cout << year_Rain << endl;

    getch();

}

float January(float)
{
    float Jan_rain;
    int days = 1;
    float rainfall = 0;
    float aggrain = 0;

    while (days <= 31) {
	cout << "nPlease enter the rainfall for day " << days << ": ";
	cin >> rainfall;
	Jan_rain += rainfall;

	days++;
    }

    return Jan_rain;


}

float February(float)
{
    float Feb_rain = 0;
    int days = 1;
    float rainfall = 0;
    float aggrain = 0;

    while (days <= 28) {
	cout << "nPlease enter the rainfall for day " << days << ": ";
	cin >> rainfall;
	Feb_rain += rainfall;

	days++;
    }

    return Feb_rain;

}

float aggRain(float Jan_rain, float Feb_rain)
{
    float total = 0;

    total = January(Jan_rain) + February(Feb_rain);

    return total;

}


If your problem considers an error your compiler provides then post the error here. I am not going to try to compile your code just to see what the undefined reference is when you were too lazy to copy the information here.
Last edited on
The implemented aggRain is not the same as the declared aggRain.

Your code has severe logical issues too.
@snowright the error produced is "undefined reference to 'aggRain(float)' "
@keskiverto you mean the fact that the function has two parameters?
Keskiverto means the implementation
1
2
3
4
float aggRain(float Jan_rain, float Feb_rain)
{
    return January(Jan_rain) + February(Feb_rain);
}

requires following declaration
 
float aggRain(float, float);

You can read more from this here http://www.cplusplus.com/doc/tutorial/functions2/

As for the logical issues try to go with this and solve them for yourself, come back if you need further help.
I actua,lly tried that before and it gave me an error for trwo few parameters in the method call in main
too few parameters*
It gave an error on the line
 
year_Rain = aggRain(total);

There should be an error, obviously, since the function requires two parameters and you only provide here one.

I must say your code contains also other basic mistakes, would you be able to read some tutorial for a while before continuing?
Last edited on
yeah I corrected that error with year_Rain = aggRain(Jan_rain,Feb_rain); but now there loops double and output the result of the second set of loops
And i might not have a choice but to read the tutorials if I wan't to get this project done by sunday
Alright, I will point some mistakes, I just got a feeling you are not learning a lot from this without reading more from some tutorial.

You do not want to do following
month_Rain = January(Jan_rain);
but instead store the value the function returns to Jan_rain so you can use it later to get the total i.e.
Jan_Rain = January( );
Do the same for Feb_rain and do not pass anything to the functions January and February, it simply does not make any sense.
After you already got the amounts of rain for the two months the function aggRain is kind of useless, you could just have
year_Rain = Jan_rain + Feb_rain;
I do not quite understand how there does not rain during other months than January and February though.
Last edited on
The reason why there's only those two months is so I can make sure each function is working before doing it for all the months
Of course, but there is no point whatsoever to write more than one function:
1
2
3
4
5
6
7
8
9
10
11
12
13
float getMonthly( const int days )
{
  float rain_total = 0.0f;
  int day = 0;
  for ( int day = 0; day < days; ++day )
    {
      cout << "nPlease enter the rainfall for day " << 1+day << ": ";
      float rainfall = 0.0f;
      cin >> rainfall;
      rain_total += rainfall;
    }
  return rain_total;
}


That does the job just fine:
1
2
Jan_Rain = getMonthly( 31 );
Feb_Rain = getMonthly( 28 );

Then, the next logical step is to store the day counts, names, and rain in array(s), and process necessary months in a loop.
Thanks much appreciated
Topic archived. No new replies allowed.