#include "stdafx.h"
#include <iostream.h>
 
struct MonthInfo
{
float totalRain;
float highTemp;
float lowTemp;
float avgTemp;
};
struct MonthInfo year[12];
int main(int argc, char* argv[])
{
const int MONTHS = 12;
// Change here
for (int i = 0 ; i < MONTHS ; i++ )
{
cout << "Enter data for month " << i << endl;
cout << "Enter Total RainFall" << endl;
cin >> year[i].totalRain;
do {
cout << "Enter High Temperature" << endl;
cin >> year[i].highTemp;
}while ( year[i].highTemp < -100 || year[i].highTemp > 140 );
do {
cout << "Enter Low Temperature" << endl;
cin >> year[i].lowTemp;
}while (year[i].lowTemp < -100 || year[i].lowTemp > 140 );
year[i].avgTemp = (year[i].highTemp + year[i].lowTemp) / 2;
}
 
float avgMonthlyRain = 0;
float sum = 0;
float monthlyTempSum = 0;
for(i = 0 ; i < MONTHS ;i++ )
{
sum += year[i].totalRain;
monthlyTempSum += year[i].avgTemp;
}
cout << "Average Monthly Rain is = " << (sum/MONTHS) << endl;
cout << "Total Rainfall for the year = " << sum << endl;
 
// Finding highest temprature
float highest = -100;
int m = 0; // for keeping the month in which highest year appeared
for (i = 0 ; i < MONTHS ; i++ )
{
if ( year[i].highTemp > highest )
{ 
highest = year[i].highTemp;
m = i;
}
}
 
cout << "Highest Temprature " << highest << " Appeared in month "<< m << endl;
 
// Finding lowest temprature for the year
float lowest = 140;
m = 0; // for keeping the month in which highest year appeared
for (i = 0 ; i < MONTHS ; i++ )
{
if ( year[i].lowTemp < lowest )
{ 
lowest = year[i].lowTemp;
m = i;
}
}
 
cout << "Lowest Temprature " << lowest << " Appeared in month "<< m << endl;
 
 
 
cout << "Average of all monthly average temperatures = " << (monthlyTempSum/ MONTHS )<<endl;
cin.get();
cin.get();
return 0;
}

Please help?

Thanx:rolleyes:

1. Please use the

tags when posting code.
It isn't like there aren't enough hints for you to do this.


2. You also need to give a better description of the problem than "it doesn't work" followed by simply dumping your code on the message board.
How "doesn't" it work.
Does it compile, if not what error messages do you get
Does it run, if not what error messages
How do the results differ from what you expect?

Just sayign doesnt work wont do.

Are you getting compile time errors, run time errors, program not functinoning as you expected ???

Explain your problem in detail and the things you are experiencing.

[edit]
Ah Mr. Salem has already brought down his MOD stick on the guy ;)
[/edit]

Apologies:

No, codes will not compile.

Errors displaying:
C:\Dev-Cpp\Statics Project.cpp In function `int main(int, char**)':
18 C:\Dev-Cpp\Statics Project.cpp `cout' undeclared (first use this function)
20 C:\Dev-Cpp\Statics Project.cpp `cin' undeclared (first use this function)

39 C:\Dev-Cpp\Statics Project.cpp name lookup of `i' changed for new ISO `for' scoping

16 C:\Dev-Cpp\Statics Project.cpp using obsolete binding at `i'

Hope this was clear.
AnG'

>>#include <iostream.h>
that file is obsolete, unless you are using a realy old compiler such as Turbo C++

#include <stream>
using std::cout;
using std::endl;
using std::cin;

>>39 C:\Dev-Cpp\Statics Project.cpp name lookup of `i' changed for new ISO `for' scoping
i declared in the for loop only has scope in the for loop. VC++ 6.0 will allow it to have scope throught the function, but that is wrong. If you want it to have scope throught the function than use C-style declaracion and declare it at the beginning of the function.

You need

#include <iostream>

And under that type:

using namespace std;

And you won't need #include "stdafx.h" either if you're using Devshed

Comments
Thanks.

Ancient Dragon:

I appreciate your help and compassion.

Regards,

AnG'

You need

#include <iostream>

And under that type:

using namespace std;

And you won't need #include "stdafx.h" either if you're using Devshed

This article has been dead for over six months. Start a new discussion instead.