I have a text file with names, wins, losse. I have to take those in a write a function to find the average, and a function to sort the names in alphabetical order. I finally got everything into arrays but I cant do anything else. I don't think I'm understanding how to call an array to divide.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int MAX_SCORES = 50;
ifstream infile;
void report(int numItems, string name[], int wins[], int losses[]);
int readData(string name[], int wins[], int losses[]);
void findAverage(int wins[], int losses[]);
int main()
{
string name[MAX_SCORES];
int wins[MAX_SCORES];
int losses[MAX_SCORES];
int numItems;
double average;
numItems = readData(name, wins, losses);
average = findAverage(wins, losses);
report(numItems,name,wins,losses);
findAverage(wins,losses);
}
int readData(string name[], int wins[], int losses[])
{
infile.open("players.txt");
int count=0;
while(infile.peek() !=EOF)
{
infile >> name[count] >> wins[count] >> losses[count];
count++;
infile.ignore(1);
}
infile.close();
return count;
}
void report(int numItems, string name[], int wins[], int losses[])
{
for (int i=0; i<numItems; i++)
cout << name[i] << " " << wins[i] << " " << losses[i] << endl;
}
void findAverage(int numItems, int wins[], int losses[])
{
double average;
for(int i= 0; i <= numItems; i++)
average= (wins[numItems]*100)/losses[numItems];
cout<< "The average value is: "<<average<<endl;
}
/*void bubbleSort (int numItems, string name[], int wins[], int losses[])
{
string temp;
int iteration;
int index;
for (iteration=1;iteration<numItems;iteration++)
{
for (index=0; index=numItems-iteration;index++)
if (name[index]>name[index+1]);
}
temp=name[index];
name[index]=name[index+1];
name[index+1]=temp;
cout << temp << endl;
}*/