Create a program to enter and average the high and low temperatures for the week
ID: 3624820 • Letter: C
Question
Create a program to enter and average the high and low temperatures for the week. Create a constant to define the size of two float arrays. Create two one dimensional float arrays in the function main() called highs and lows.const int MAX = 7 float highs[MAX]; float lows[MAX]; Write a loop to ask the user to enter the highs until the size of the array is reached. Write a similar loop to ask the user to enter the lows until the size of the array is reached. Use the defined constant (as shown above) when checking for the maximum size of each array. Calculate the average high for the week Calculate the average low for the week Display those results
Explanation / Answer
Something like this should work: #include #include int main(void) { const int MAX = 7; float highs[MAX]; float lows[MAX]; float average_high = 0; float average_low = 0; int i; //use a for loop to get all the high temps, then do same for low temps for(i=0; i highs[i]; //while you collect the data, keep track of the total sum so you can //find the average later average_high += highs[i]; } for(i=0; i lows[i]; //while you collect the data, keep track of the total sum so you can //find the average later average_low += lows[i]; } //you have the sums, now just divide by MAX to find averages average_high = average_high/MAX; average_low = average_low/MAX; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.