I am writing a program where you type in the highs and lows for the week and it averages them and tells you the highest and lowest temperature. I would like it to ask the high for Sunday then the low for Sunday, then the high for Monday and so on. I can't seem to get the days in order and the average, highest, and lowest function won't work for me. Any help on what I should do would be greatly appreciated :D

#include <iostream>
#include <iomanip>
using namespace std;
void main(void)
{
const int   MAX = 7;        
float       highs[MAX];    
float       lows[MAX];  
int         count = 0;
int         counts = 0;         
int         x, i;           


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

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

    float sum = 0.0;
    for (int i=0; i < MAX; i++)
    {
        sum += lows[i];
    }
    cout << "The average temperatures is: " << (highs[counts] + lows[counts])/14 << "\n";
    cout << "Minimum value: " << lows[counts-1] << '\n';
    cout << "Maximum value: " << highs[counts+1] << '\n';

    system("pause");
}

Recommended Answers

All 4 Replies

My new code but still, I have something wrong. Any help?

#include <iostream>
#include <iomanip>
using namespace std;
void main(void)
{
const int   MAX = 7;        
float       highs[MAX];    
float       lows[MAX];  
int count = 0;
do
{
cout << endl;
int DAYS[7];
cout << "Enter the high temperature for ";DAYS[count];": ";
DAYS[0];"Sunday";
DAYS[1];"Monday";
DAYS[2];"Tuesday";
DAYS[3];"Wednesday";
DAYS[4];"Thursday";
DAYS[5];"Friday";
DAYS[6];"Saturday";
cin >> highs[count];
cout << endl;
if highs[count]==0 count=MAX else
{
int DAYS[7];
cout << "Enter the low temperature for "DAYS[count]": ";
DAYS[0];"Sunday";
DAYS[1];"Monday";
DAYS[2];"Tuesday";
DAYS[3];"Wednesday";
DAYS[4];"Thursday";
DAYS[5];"Friday";
DAYS[6];"Saturday";
cin >> lows[count];
cout << endl;
if lows[count]==0 count=MAX else count++;
}
} while (count < MAX);

float sum = 0.0;
float highest = highs[0];
float lowest = lows[0];
for (int i=1; i < MAX; i++)
{
sum += lows[i]+highs[i];
if highest < high[i]
highest = high[i];
if lowest > low[i]
lowest = low[i];
}
cout<< "The average temperatures is: " << (sum/14) << "\n";
cout << "Minimum value: " << lowest << '\n';
cout << "Maximum value: " << highest << '\n';

    system("pause");
    return 0;
}

for a complete cout statement replace the semicolon with <<
next if you want to accept values for the Days array then use cin for each of the indexes

for the if statements your missing the parentheses to hold the condition

Still showing some errors. Did I fix what you were saying.

#include <iostream>
#include <iomanip>
using namespace std;
void main(void)
{
const int   MAX = 7;        
float       highs[MAX];    
float       lows[MAX];  
int count = 0;
do
{
cout << endl;
{
int DAYS[7];
cout << "Enter the high temperature for ";DAYS[count];": " << endl;
DAYS[0];"Sunday";
cin >> highs[count];
DAYS[1];"Monday";
cin >> highs[count];
DAYS[2];"Tuesday";
cin >> highs[count];
DAYS[3];"Wednesday";
cin >> highs[count];
DAYS[4];"Thursday";
cin >> highs[count];
DAYS[5];"Friday";
cin >> highs[count];
DAYS[6];"Saturday";
cin >> highs[count];
cout << endl;
if highs[count]==0 count=MAX else
}
{
int DAYS[7];
cout << "Enter the low temperature for "DAYS[count]": " << enl;
DAYS[0];"Sunday";
cin >> lows[count];
DAYS[1];"Monday";
cin >> lows[count];
DAYS[2];"Tuesday";
cin >> lows[count];
DAYS[3];"Wednesday";
cin >> lows[count];
DAYS[4];"Thursday";
cin >> lows[count];
DAYS[5];"Friday";
cin >> lows[count];
DAYS[6];"Saturday";
cin >> lows[count];
cout << endl;
if lows[count]==0 count=MAX else count++;
}
while (count < MAX);

float sum = 0.0;
float highest = highs[0];
float lowest = lows[0];
for (int i=1; i < MAX; i++)
{
sum += lows[i]+highs[i];
if highest < high[i]
highest = high[i];
if lowest > low[i]
lowest = low[i];
}
cout<< "The average temperatures is: " << (sum/14) << "\n";
cout << "Minimum value: " << lowest << '\n';
cout << "Maximum value: " << highest << '\n';

    system("pause");
    return 0;
}

cin >> highs[count];

since you don't increment the value of count every time you used this you overwrite the current value with the new value

cout << "Enter the high temperature for ";DAYS[count];": " << endl;
DAYS[0];"Sunday";

when you use the semicolon you end the statement (here the cout statement) which means here the code following the first semicolon doesn't make sense
like I said with my previous comment:

for a complete cout statement replace the semicolon with <<

but the arrays days is not yet initialized so it wouldn't print a value if you want to use accept values for the array use cin also don't forget to increment the index

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.