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;
#include<iostream>
#include<math.h>
#include<conio.h>
usingnamespace 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.
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.
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( constint 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;
}