Getting data from file using 2D arrays
I need to figure how to make this program to get the info from the file below correctly...
THis is a sample of the data file---
Furyk,Jim 65 66 66 68
Azinger,Paul 67 70 65 69
woods,tiger 69 68 70 70
ells,ernie 68 70 68 74
mercer,brian 70 71 71 72
the program ---
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h> //used for stream programs
#include <string.h>
const int MAX = 50;
void input_data(char name[][30], int round1[], int round2[], int round3[], int round4[], int & player_count);
void compute_scores(char name[][30],int round1[], int round2[], int round3[], int round4[],int round5[], float average[]);
main()
{
char name [MAX][30];
int round1 [MAX];
int round2 [MAX];
int round3 [MAX];
int round4 [MAX];
int round5 [MAX];
float average [MAX];
int player_count;
input_data(name, round1, round2, round3, round4, player_count);
compute_scores(name, round1, round2, round3, round4, round5, average);
return 0;
}
void input_data (char name[][30],int round1[], int round2[], int round3[], int round4[], int & player_count)
{
ifstream infile;
int count;
infile.open ("scores.dat");
if (!infile)
cout << " **** Can't open the data file!!! **** ";
count = 0;
player_count=0;
while (infile)
infile >> name [count][30] >> round1[count] >> round2[count] >> round3[count] >> round4[count];
{
count++;
player_count++;
}
}
void compute_scores (char name[][30],int round1[], int round2[], int round3[], int round4[],int round5[], float average[])
{
int i;
int pass;
int hold;
for ( i =0; i< MAX; i++)
round5[i] = round1[i] + round2[i] + round3[i] + round4[i];
for (pass = 0; pass < MAX - 1; pass++)
for (i= 0; i < MAX-1; i++ )
if (round5 [i]< round5 [i+1])
{
hold = round5[i];
round5 [i] = round5[i+1];
round5[i+1] = hold;
}
for (i=0; i < MAX; i ++)
cout << name << round1[i] << round2[i] << round3[i] << round4[i] << endl;
}
// Thank You