Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help finding the lowest and highest temperatures. //Libraries #include <i

ID: 3542858 • Letter: I

Question

I need help finding the lowest and highest temperatures.

//Libraries

#include <iostream>

#include <string>

using namespace std;

//Structure

struct months

{

float rain;

float high;

float low;

float average;

};

//Main begins here

int main()

{

//Declare variables

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"};

//loop to find rain and temps

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;

//input validation

while(total[i].high<-100||total[i].high>140)

{

cout << endl;

cout<<"Invalid entry-must be between -100 through 140 ";

cout<<"high temperature: ";

cin>>total[i].high;

cout << endl;

}

cout << endl;

cout << "Enter the lowest temperature for this month: ";

cin >> total[i].low;

//Input validation

while(total[i].low<-100||total[i].low>140)

{

cout << endl;

cout<<"Invalid entry-must be between -100 through 140 ";

cout<<"high temperature: ";

cin>>total[i].low;

cout << endl;

}

//Calulate the average temperature

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;

}

?

?

?

Explanation / Answer

please rate - thanks


you didn't say highest of what, and lowest or what,

it looked like you wanted highest high and lowest low, so did that

//Libraries

#include <iostream>

#include <string>

using namespace std;

//Structure

struct months

{

float rain;

float high;

float low;

float average;

};

//Main begins here

int main()

{

//Declare variables

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"};

//loop to find rain and temps

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;

//input validation

while(total[i].high<-100||total[i].high>140)

{

cout << endl;

cout<<"Invalid entry-must be between -100 through 140 ";

cout<<"high temperature: ";

cin>>total[i].high;

cout << endl;

}

cout << endl;

cout << "Enter the lowest temperature for this month: ";

cin >> total[i].low;

//Input validation

while(total[i].low<-100||total[i].low>140)

{

cout << endl;

cout<<"Invalid entry-must be between -100 through 140 ";

cout<<"high temperature: ";

cin>>total[i].low;

cout << endl;

}

//Calulate the average temperature

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)

{

highest=i;

}

if(total[i].low <total[lowest].low)

{

lowest=i;

}

}

cout << endl;

cout << "The total rainfall for the year was: " << totalRain << endl;

cout << "The highest temperature was: "<<total[highest].high << endl;

cout << "The lowest temperature was: "<< total[lowest].low<<endl;

system("PAUSE");

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote