Create a program to enter and average the high and low temperatures for the week
ID: 3647101 • 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.
Display the difference for each day
Explanation / Answer
#include #include #include using namespace std; //******function prototypes******** void getTemps(int xTemps[2][7]); void avgTemps(int xTempsX[2][7], double &high, double &low); int main () { //declare variables int temperatures = 0; const int DAYS = 7; const int TEMPS = 2; //declare array int temps[TEMPS][DAYS] = {0}; //asks for high and low temperatures getTemps(temps); //sets the two averages double avgHigh, avgLow; //calculates the average of the two arrays avgTemps(temps, avgHigh, avgLow); system("pause"); return 0; } //*****Functions***** void getTemps(int xTemps[2][7]) { for(int i = 0; i < 7; i++) { cout > xTemps[0][i]; cout > xTemps[1][i]; } } void avgTemps(int xTempsX[2][7], double &high, double &low) { high = 0; low = 0; for(int j = 0; j < 7; j++) { high += xTempsX[0][j]; low += xTempsX[1][j]; } high = high / 7; low = low / 7; 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.