I have a student name, wins, losses. In that order in a txt file.
I'm trying to read it in and them print it out, but i'm not real sure what I'm doing

#include <iostream>
#include <fstream>
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[]);

int main()
{

string name[MAX_SCORES];
int wins[MAX_SCORES];
int losses[MAX_SCORES];
int numItems;

numItems = readData(name, wins, losses);

}

int readData(string name[], int wins[], int losses[])
{
	infile.open("players.txt");
	
	int count=0;
	while(infile.peek() !=EOF)
	{
		infile >> name[count];
		infile >> wins[count];
		infile >> 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;
}

What is happening, what problems are occurring? As it is now, the program won't actually do anything, as you never call report() .

Good catch. Didn't notice that.

#include <iostream>
#include <fstream>

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[]);

int main()
{

string name[MAX_SCORES];
int wins[MAX_SCORES];
int losses[MAX_SCORES];
int numItems;

numItems = readData(name, wins, losses);
report(name,wins,losses);

}

int readData(string name[], int wins[], int losses[])
{
	infile.open("players.txt");
	
	int count=0;
	while(infile.peek() !=EOF)
	{
		infile >> name[count];
		infile >> wins[count];
		infile >> 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;
}

PlayerRankings.cpp: In function 'int main()':

PlayerRankings.cpp:21: error: invalid conversion from 'std::string*' to 'int'

PlayerRankings.cpp:21: error: cannot convert 'int*' to 'std::string*' for argument '2' to 'void report(int, std::string*, int*, int*)'

You forgot to include the first argument of the report() function ( numItems ).

YES! Thanks Schoil-R-LEA, you are the ish.

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.