I am attempting to complete a homework assignment. The progam basically requires input from the keyboard into an array and then to perform some calculations on the input information. I believe I can do the calculations, but I cannot figure out how to get the input into the array. The assignment requires a two-dimensional array. My book, all examples from the instructor, everything on the internet ( I have tried everything I know) initializes the array with static values. I cannot figure out how to make the input data go into the array to be manipulated. Please provide me with a direction to go I am stumped. I have attached what I have so far.

In a loop which runs 12 times, you want

cin >> temps[0][col];  // this is max
cin >> temps[1][col];  // this is min

Thanks for the direction.

Ok, I have attached my new stab at it. Let me note that I don't really have to ouput the array, I just put that in so I could see what was going on. However, I still don't think it's quite right because this is what I get:
Enter high temperature for each month
1 2 3 4 5 6 1 2 3 4 5 6 (my entry)
2 (output)
3
4
5
6
1
2
3
4
5
6

1 2 3 4 5 6 1 2 3 4 5 6 (my entry, no prompt)
1 (output)
2
Enter low temperatures for each month
4
5
6
1
2
3
4
5
6.

Obviously, I want all the numbers to appear and then I want the prompt for the next set of numbers. It seems that my prompt is being made part of the array, but I can't figure out how to fix it. And where is the number 1 from the first array? Help!

Member Avatar for iamthwee

It's fairly simple use a separate for loop for both input and output:-

i.e

#include <iostream>
#include <iomanip>
#include <cstdlib> 

using namespace std;
const int rowSize = 2;
const int colSize = 12;
int main()
{
  int temps [rowSize][colSize];
  int temp1;
  int temp2;
  int rows;
  int cols;
  cout << "Enter high temperature for each month" << endl;
  
  //for (int rows=0; rows<1; rows++)
  for ( int cols = 0; cols <= 12; cols++ )
  {
    cin >> temps[0][cols]; 
  }

  //print em
  for ( int cols = 0; cols <= 12; cols++ )
  {
    cout << temps[0][cols] << " ";
  }
  cin.get();
  cin.get();
}

Ok,
I am making progress. Now my issue is that when I try to average, I get the average of the second set of numbers for both high and low temperatures. I can't determine how to separate the two. A little assistance please?

Thanks,

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.