Declare a seven-row, two-column int array named temperatures.
The program should prompt the user to enter the highest and lowest temperatures for seven days.
Store the highest temp in the first column and the lowest in the second column.
The program should display the average high and average low for the week.
Additionally, show the highest and lowest temperature along with the day number.

ok what about you start coding and let us help you in the problems that you face

ok what about you start coding and let us help you in the problems that you face

OK, here is what I have so far...

``````include "stdafx.h"
#include "iostream"
#include "iomanip"
#include "cmath"
#include "string"

using namespace std;

int main ()
{
//declare array
int temp[7][2]= {0};
int day = 0;
int lowtemp = 0;
int hightemp = 0;
int row = day;

//enter data into array

cout<<"Enter Day:"<<endl;
cin>>day;
cout<<"Enter low temperature:"<<endl;
cin>>lowtemp;
cout<<"Enter high temperature:"<<endl;
cin>>hightemp;

system("pause");
return 0;
}``````

First, I can't figure out how to specify what goes into each column hightemp in first and low temp in second.
Second, I have tried to write the "for" statement for a loop, so it will calculate the average temp for the 7 days, but have failed miserably. Any help is greatly appreciated.

Here are some suggestions:

You can call temp[ ][0] the low for that day and temp[ ][1] the high, and maybe you could do your input something like this:

``````#include "iostream"
#include "iomanip"
#include "cmath"
#include "string"
using namespace std;

int main()
{
//declare array
int temp[7][2]= {0};
int day = 0;
//int lowtemp = 0;
//int hightemp = 0;

//enter data into array

cout<<endl<<"Enter Day: ";
cin >> day;
cout << "\nEnter low temperature: ";
cin >> temp[day][0];
cout << "\nEnter high temperature: ";
cin >> temp[day][1];

//test
cout << "\nDay: " << day << "  High: " << temp[day][1] << "  Low: " << temp[day][0] <<endl;

system("pause");
return 0;
}``````

Of course, you would have to loop around this code to get all of the days entered in and then have a means for exiting the loop once all of the days were entered.

To add up all of the high temps -

``total = temp[0][1] + temp[1][1] + temp[2][1] + temp[3][1] + temp[4][1] + temp[5][1], etc.``

...and temp[x][0] for the lows. Of course you would use a loop for that.

Thanks so much for your help!!

Thanks so much for your help!!

If you are supposed to use the variables lowtemp and hightemp (which is a good idea anyway), then you can do this:

``````#include "iostream"
#include "iomanip"
#include "cmath"
#include "string"
using namespace std;

int main()
{
//declare array
int temp[7][2]= {0};
int day = 0;
const int lowtemp = 0;
const int hightemp = 1;

//enter data into array

cout<<endl<<"Enter Day: ";
cin >> day;
cout << "\nEnter low temperature: ";
cin >> temp[day][lowtemp];
cout << "\nEnter high temperature: ";
cin >> temp[day][hightemp];

//test
cout << "\nDay: " << day << " High: " << temp[day][hightemp] << " Low: " << temp[day][lowtemp] <<endl;

system("pause");
return 0;
}``````

All we are doing here is replacing 0 and 1 with lowtemp and hightemp for clarity. And when we use the keyword "const" (constant) we are just telling the compiler to act as a watchdog for us, to keep an eye out to make sure we don't accidently change lowtemp or hightemp to something else. These two variables will never hold the value of the low or high temperatures themselves, but rather are an indice into the array where the actual temps are stored. For example, to add up the high temps:

``Total = temp[0][hightemp] + temp[1][hightemp] + temp[2][hightemp], etc.``

So "hightemp" just represents 1 for clarity - that's all. So we don't ever want to change that since it is only an indice into the array where hightemp is actually stored.
The array that you are using has 14 memory locations (7 x 2), and thus can store 14 integers. And each of those 14 variables needs two indices to locate it, like [day][lowtemp]. So together those two numbers, or indices, represent one variable. So you could say for example:

``````if(temp[2][hightemp] > 90)
cout << "Temperature on Tuesday was too hot!";``````

You could think of your data in the array as 7 pairs of integers (high and low temps), and each pair is selected by a number 0 - 6 (Sun - Sat) and then one of the numbers in the pair is selected by 0 or 1 (lowtemp or hightemp). You do have to be careful thgough, that you don't go beyond the bounds of the array, like temp[8][1] or temp[9][4] or else you will be corrupting some other portion of memory.

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.