The point is to read a file and then display the information from a 2D array. Then find the highest value in each column and divide all the numbers in each column by the high value for that column. Then display the quotients (which I put back into the original 2D array and then reprinted it). Its all straight out with no functions. But well separated with comments. I can't get the file to read. That is my first problem, so I can't even continue to debug the rest. If it helps the file data is this:
1.267 0.167 0.250 2.670 1.000
3.240 0.376 0.375 3.400 1.128
7.564 0.668 0.500 4.303 1.270
5.041 1.043 0.625 5.313 1.410
4.660 1.502 0.750 7.650 1.693
5.727 2.044 0.875 3.600 2.257
#include <iostream>
#include <fstream>
#include<iomanip>
using namespace std;
// Globals
const int max_rows = 6, max_cols = 5;
// Declarations
int i, j, sub, num_rows, num_cols;
int max_value[max_cols], num_array [max_rows][max_cols];
ifstream infile ("C:\\wk03_data(2010.04).txt");
int main()
{
// Read file into array
infile>> num_rows>> num_cols;
for (i = 0; i < num_rows; i++)
{
for (j = 0; j < num_cols; j++)
{
infile>>num_array [i][j];
}
}
// Print array
for (i = 0; i < num_rows; i++)
{
for (j = 0; j < num_cols; j++)
{
cout<< num_array[i][j]<< " ";
}
cout<< endl;
}
// Find max values
sub = 0;
i = 0, j = 0;
max_value[sub] = num_array[i][j];
for (i = 0; i < num_rows; i++)
{
while (num_array[i][j] < num_array[i+1][j])
{
max_value[sub] = num_array[i+1][j];
}
}
sub = 1;
i = 0, j = 1;
max_value[sub] = num_array[i][j];
for (i = 0; i < num_rows; i++)
{
while (num_array[i][j] < num_array[i+1][j])
{
max_value[sub] = num_array[i+1][j];
}
}
sub = 2;
i = 0, j = 2;
max_value[sub] = num_array[i][j];
for (i = 0; i < num_rows; i++)
{
while (num_array[i][j] < num_array[i+1][j])
{
max_value[sub] = num_array[i+1][j];
}
}
sub = 3;
i = 0, j = 3;
max_value[sub] = num_array[i][j];
for (i = 0; i < num_rows; i++)
{
while (num_array[i][j] < num_array[i+1][j])
{
max_value[sub] = num_array[i+1][j];
}
}
sub = 4;
i = 0, j = 4;
max_value[sub] = num_array[i][j];
for (i = 0; i < num_rows; i++)
{
while (num_array[i][j] < num_array[i+1][j])
{
max_value[sub] = num_array[i+1][j];
}
}
// Divide each number in a column by the columns highest value
i = 0, j = 0, sub = 0;
for (i = 0; i < num_rows; i++)
{
num_array[i][j] = num_array[i][j] / max_value[sub];
}
i = 0, j = 1, sub = 1;
for (i = 0; i < num_rows; i++)
{
num_array[i][j] = num_array[i][j] / max_value[sub];
}
i = 0, j = 2, sub = 2;
for (i = 0; i < num_rows; i++)
{
num_array[i][j] = num_array[i][j] / max_value[sub];
}
i = 0, j = 3, sub = 3;
for (i = 0; i < num_rows; i++)
{
num_array[i][j] = num_array[i][j] / max_value[sub];
}
i = 0, j = 4, sub = 4;
for (i = 0; i < num_rows; i++)
{
num_array[i][j] = num_array[i][j] / max_value[sub];
}
// Display each quotient
for (i = 0; i < num_rows; i++)
{
for (j = 0; j < num_cols; j++)
{
cout<< num_array[i][j]<< " ";
}
cout<< endl;
}
}