help with with arrays and functions

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
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#define MAX 100
using namespace std;
/**************PROTOTYPES*******************/
int read(float score[],float &totalscore,int & numgrades, int max);


/*************MAIN***************************/
void main()
{
	float score[MAX], totalscore = 0;
	int	  numgrades = 0, limit;

	limit=read(score,totalscore,numgrades,MAX);
	
	cout<<endl<< totalscore<<endl<<limit;

}
/******************ENDOFMAIN************************/
int read(float score[],float &totalscore,int & numgrades, int max)
{
	ifstream fin;
	string filename;
	int i=0;
	cout<<"Enter file name:";
	getline (cin, filename);
	fin.open(filename.c_str());
		if ( fin.fail() )
		{
			cout <<endl <<"Bad File Name" <<endl;
			return 0;
		}

			while(!fin.eof() && i < max)
			{
				fin>>score[i];
				numgrades++;
				totalscore+=score[i];
				if( i == max )
				{
				cout<<endl<<"Array is full and can not accomodate all data.\n";
				break;
				}
				i++;
			}

		return (i);
}



when i run the program i get totalscore as some weird number. help on how to fix it
Last edited on
the data file on consist of numbers ranging from 0 thru 100.
I hope this is a cpp file. main should be returning int not void. Ideally the program should not have been compiled.
After the modification the program should work fine.
Meanwhile, if possible attach the snapshot of the data file.
Topic archived. No new replies allowed.