Hello, first time here in the forum, though Ive used it before for help.
Okay so I have to create a constant to define the size of two float arrays and
Create two one dimensional float arrays in the function main() called highs and lows.
const int MAX = 7
float highs[MAX]; // like this
float lows[MAX];
Though I can get to print out the high and low temperatures, I cannot get the program to average the low or the high temperatures. Can anyone explain to me what I did wrong on the for loop for the average?
P.S. In my code I only have the for loop to average the low temperatures.
Thanks in advance.
#include <iostream>
#include <iomanip>
using namespace std;
void main(void)
{
const int MAX = 7; // max size of the array
float highs[MAX];
float lows[MAX];
int count;
int counts; // # of temps entered
int x; // loop control variable (LCV)
int i = MAX;
// load the array from the keyboard
do {
cout << "Enter the high temperatures ";
cin >> highs[count];
count++;
cout << endl;
} while ( ( count < MAX) && ( highs[count-1] != 0) );
if ( highs[count-1] == 0)
{
count--;
}
// print them back out
for (x= 0; x < count; x++)
{
cout << "High Temperature[" << x << "] = " << highs[x] << endl;
}
cout << "\n\n";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
do {
cout << "Enter the low temperatures ";
cin >> lows[counts];
counts++;
cout << endl;
} while ( ( counts < MAX) && ( lows[counts-1] != 0) );
if ( lows[counts-1] == 0)
{
counts--;
}
for (x= 0; x < counts; x++)
{
cout << "Low Temperature[" << x << "] = " << lows[x] << endl;
}
double sum = 0;
for (int i=0; i <7; i++)
{
sum += lows[MAX];
}
cout << "The average low temperatures is: " << sum/7<< "\n";
system("pause");
}