### Help with finding higest and lowest

How can I properly find the lowest and the highest temperatuers?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` ``````#include #include using namespace std; struct months { float rain; float high; float low; float average; }; int main() { const int month= 12; months total[month]; float totalRain=0; int highest = 0; int lowest = 0; string monthName[month]={"January","February","March","April","May","June","July","August", "September","October","November","December"}; for(int i=0; i<12; i++){; cout << monthName[i] << endl; cout << endl; cout << "Enter total rain for this month: "; cin >> total[i].rain; cout << endl; cout << "Enter the highest temperature for this month: "; cin >> total[i].high; while(total[i].high<-100||total[i].high>140) { cout << endl; cout<<"Invalid entry-must be between -100 through 140\n"; cout<<"high temperature: "; cin>>total[i].high; cout << endl; } cout << endl; cout << "Enter the lowest temperature for this month: "; cin >> total[i].low; while(total[i].low<-100||total[i].low>140) { cout << endl; cout<<"Invalid entry-must be between -100 through 140\n"; cout<<"high temperature: "; cin>>total[i].low; cout << endl; } cout << endl; cout << endl; total[i].average = (total[i].high+total[i].low)/2; cout <<"The avearge temperature of this month is: " << total[i].average; cout << endl; cout << endl; totalRain+=total[i].rain; if(total[i].high>total[highest].high) { i=highest; } if(total[i].low >total[lowest].low) { i=lowest; } } cout << endl; cout << "The total rainfall for the year was: " << totalRain << endl; cout << highest << endl; cout << lowest; system("PAUSE"); return 0; }``````
Last edited on
float lowestTemp = 140;
string = lowestMonth;

for(int i=0; i<12; i++){;

if (lowestTemp > total[i].low);
lowestTemp = total[i].low;
lowestMonth = monthName[i];
}

You'll probably have to clean that up alot to get it to work, but I think thats the basic logic of it. Let me know how it works out for you.
Topic archived. No new replies allowed.