Help with 2D arrays based on user input

The first thing to do is list your requirements.
• Calculate and store all windchill values in a two-dimensional (2D) array.
• Read from the 2D array in order to display all windchill values in a well-formatted table using loops.
• Make sure to set the precision of your floating-point numbers so that only 1 digit is displayed to the right of the decimal point.
• Moreover, all data in each column of your table must be aligned about the decimal point in each number.

Before you do any of that, just try to do the calculation.
> 𝑇wc = 35.74 + 0.6215𝑇a − 35.75𝑉^0.16 + 0.4275𝑇aV^0.16
1
2
3
4
5
6
for ( double Ta = startTemp ; Ta <= endTemp ; Ta += tempInt ) {
  for ( double V = startWind ; V <= endWind ; V += windInt ) {
    double Twc = 35.74 + 0.6215*𝑇a - 35.75*pow(𝑉,0.16) + 0.4275*𝑇a*pow(V,0.16);
    cout << Twc << endl;
  }
}

Check at this stage that you're actually getting meaningful results.
A nicely formatted table of garbage is considerably less useful than badly formatted correct data.

Then you can start refining the program ONE bullet point at a time.

> int** windChill= new int* [rowCounter * columnCounter];
Are you required to dynamically allocate your array, or could you get away with say
double windChill[100][100];
Even if you HAVE to dynamically allocate, starting with the fixed array is a useful intermediate step.

int** windChill= new int* [rowCounter * columnCounter];

std::vectors would work remarkably easier, no need to worry about manually allocating memory and the headaches that result.

std::vector<std::vector<int>> windChill(rowCounter, std::vector<int>(columnCounter, 0));
Well now you need to separate the calculation and printing into separate loops.

Like
 
windChill[row][col] = Twc;



And then sometime later, in another loop construct.
 
cout << setw(6) << showpoint << windChill[row][col] << endl;
Topic archived. No new replies allowed.