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;
{
[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;
}
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.