Operand >> illegal

Trying to find which section has a higher average from 2 existing files (notepads)then writing the result to a third. However i'm getting that last 1,last 2, first 1, and first 2 are illegal function definitions or some such error. This is the first time i use files so any hints would be appreciated.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


int main ()
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
{
	[double average1;
	double average2;

	double grade1;
	double grade2;

	double sum1;
	double sum2;
	sum1=0;
	sum2=0;

	char first1 {50};                   //First name
	char last1 {50};                    //Last name
	char first2 {50};
	char last2 {50};


	double gradecount1;
	double gradecount2;
	gradecount1=0;
	gradecount2=0;
	
	ifstream inClientFile1("eece331sec1*.txt");                  //First file opening
	
	if (!inClientFile1)
		{
			cerr<<"File could not be opened!";
			exit(1);	
		}

	if (inClientFile1.is_open())
	{
		while (first1>>" ">>last1>>" ">>grade1)              //reading the file
		{
			sum1=sum1+grade1;
			gradecount1++;
		}
	
		average1=floor(sum1*100/gradecount1+0.5)/100;             //First average computed
	}

	ifstream inClientFile2("eece331sec2*.txt");                    //Second file opening
		
	if(!inClientFile2)
		{
			cerr<<"File could not be opened!";
			exit(1);
		}

	if (inClientFile2.is_open)
	{
		while (first2>>" ">>last2>>" ">>grade2)          //reading the file
		{
			sum2=sum2+grade2;
			gradecount2++;
		}

		average2=floor(sum2*100/gradecount2+0.5)/100;           //Second average computed
	}

	if (average2>average1)                                                          //Comparing averages to determine what should be written
	{
		ofstream outClientFile1("eece331secresults*.txt");
		{
			cout<<"Section 2 has a higher average: "<<average2;
		}
	}
	if (average1>average2)
	{
		ofstream outClientFile2("eece331secresults*.txt");
		{
			cout<<"Section 1 has a higher average: "<<average1;
		}
	}
	if (average1==average2)
	{
		ofstream outClientFile3("eece331secresults*.txt");
		{
			cout<<"Both sections had an average of: "<<average1;
		}
	}
return 0;
}
Last edited on
There's other errors I think but foremost, you should change void main() to int main().

You should also put your code around code tags [code](code here)[/code] for proper readability and indentation.

Other stuff:
* can't be used in a file name is most OSes, so your file streams will most likely fail to open.
~line 57, is_open needs to have parenthesis after it, it's a function.

and what are you trying to here?
 
while (first1>>" ">>last1>>" ">>grade1)
Last edited on
That was trying to add the spaces, although come to think of it i shouldn't have added them. That's trying to read the file
Last edited on
See the format section to the left right (edit: wow...) of your post when you click edit? Highlight your code and then press the [<>] button.
Last edited on
Never mind, i got how to solve it
Last edited on
Topic archived. No new replies allowed.