why wont my program let me enter data

I know I'm not using all my functions at this time but I need to test to make sure I can enter data and as of now I can get my code to finally compile but it wont let me enter data. user names will be used to give credit for helping.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 #include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int ARRAY_SIZE = 2 ; // declare my constant for array size to make it easier to change amount of players being entered

// struct to hold MLB player stats
struct playerStats
{
	string playerName[ARRAY_SIZE] ; // array containing player names
	int home_runs[ARRAY_SIZE] ;     // array containing number of home runs
	int hits[ARRAY_SIZE] ;			// array containing number of hits
}tempStats;				// variable of struct
 


// function prototypes
void intro() ;
playerStats playerInfo() ;
void dataOutput(playerStats myPlayers) ;
void openFiles(ifstream& fin, ofstream& fout) ;
void closeFiles(ifstream& fin, ofstream& fout) ;
void dataOutputToFile(playerStats myPlayers, ofstream& fout) ;


int main()
{
	ifstream fin ;
	ofstream fout ;

	intro() ;
	playerStats playerInfo() ;
	

	
	system ("PAUSE") ;

	return 0 ;
 }


//functions

void intro()
{
	cout << " This program allows the user to enter in the stats of 10 MLB players." << endl << endl ;
}

playerStats playerInfo()
{
	playerStats tempStats ;

	for(int i=0 ; i < ARRAY_SIZE ; i++)
	{

		cout << "Enter the player's name: ";
		cin >> tempStats.playerName[i] ;
	
		cout << "Enter the player's number of homeruns: ";
		cin >> tempStats.home_runs[i] ;
	
		cout << "Enter the player's number of hits: ";
		cin >> tempStats.hits[i] ;
	
		cout << endl ;
	}

	return tempStats ;
}

void dataOutput(playerStats myPlayers)
{
	

	 for(int i=0 ; i < ARRAY_SIZE ; i++)
	 {
		 cout << myPlayers.playerName[i] 
			  << " has "<< myPlayers.home_runs[i] 
		      << " homeruns and " 
		      << myPlayers.hits[i] << " hits" << endl ;
	 }
}
void dataOutputToFile(playerStats myPlayers, ofstream& fout)
{
	

	 for(int i=0 ; i < ARRAY_SIZE ; i++)
	 {
		 fout << myPlayers.playerName[i] 
			  << " has "<< myPlayers.home_runs[i] 
		      << " homeruns and " 
		      << myPlayers.hits[i] << " hits" << endl ;
	 }
}
void openFiles(ifstream& fin, ofstream& fout)
{
	string filename ;

	cout << "Enter the location of your input file: " ;
	cin >> filename ;

	fin.open(filename.c_str()) ; // Open input file
	
	cout << "Enter the location of your output file: " ;
	cin >> filename;
	
	fout.open(filename.c_str()) ; // Open output file

} // end openFiles function

void closeFiles(ifstream& fin, ofstream& fout)
{

	fin.close() ; // close input file
	fout.close() ; // close output file

} // end closeFiles function
Try just typing playerInfo() ;

1
2
intro() ;
playerStats playerInfo() ; //prototype 
Last edited on
for the life of me Olysold I tried that earlier and it didnt work but I tried it again and sure enough it worked. been fixing my code little by little. Thank you and I will use your screen name to give you credit for helping.
Also consider reading through: http://www.cplusplus.com/forum/articles/6046/
Topic archived. No new replies allowed.