edbtzy
12-05-2008, 03:24 AM
I wrote my whole code out but i am getting these errors:
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(94) : error C2601: 'calculateaverage' : local function definitions are illegal
1> c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(18): this line contains a '{' which has not yet been matched
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(108) : error C2601: 'calculategrade' : local function definitions are illegal
1> c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(18): this line contains a '{' which has not yet been matched
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(134) : error C2958: the left parenthesis '(' found at 'c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(111)' was not matched correctly
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(136) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(18)' was matched
here is my code:
// new.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using std::cout;
using std::cin;
using std::endl;
using namespace std;
void calculateaverage(ifstream& input, ofstream& output, double& average);
char calculategrade(double mean);
int _tmain(int argc, _TCHAR* argv[])
{
int count=0;
double studentaverage, classaverage, classtotal=0;
char studentgrade;
string studentname;
ifstream infile;
ofstream outfile;
infile.open("scores.txt");
outfile.open("outfile.txt");
cout<<setw(10)<<left<<"Student";
cout<<setw(10)<<left<<"Test 1";
cout<<setw(10)<<left<<"Test 2";
cout<<setw(10)<<left<<"Test 3";
cout<<setw(10)<<left<<"Test 4";
cout<<setw(10)<<left<<"Test 5";
cout<<setw(10)<<left<<"Average";
cout<<setw(10)<<left<<"Grade";
cout<<endl;
outfile<<setw(10)<<left<<"Student";
outfile<<setw(10)<<left<<"Test 1";
outfile<<setw(10)<<left<<"Test 2";
outfile<<setw(10)<<left<<"Test 3";
outfile<<setw(10)<<left<<"Test 4";
outfile<<setw(10)<<left<<"Test 5";
outfile<<setw(10)<<left<<"Average";
outfile<<setw(10)<<left<<"Grade";
cout<<endl;
cout.precision(0);
outfile.precision(0);
cout<<fixed;
outfile<<fixed;
while (!infile.eof())
{
studentaverage=0;
infile>>studentname;
cout<<setw(10)<<left<<studentname;
outfile<<setw(10)<<left<<studentname;
calculateaverage(infile, outfile, studentaverage);
cout<<setw(10)<<right<<studentaverage;
outfile<<setw(10)<<right<<studentaverage;
studentgrade=calculategrade(studentaverage);
cout<<setw(8)<<right<<studentgrade<<endl;
classtotal += studentaverage;
count++;
{
cout<<endl;
outfile<<endl;
cout<<"Class Average";
outfile<<"Class Average";
classaverage=classtotal/count;
cout<<setw(57)<<right<<classaverage;
outfile<<setw(57)<<right<<classaverage;
cout<<setw(8)<<right<<calculategrade(classaverage)<<endl;
outfile<<setw(8)<<right<<calculategrade(classaverage)<<endl;
}
return 0;
}
void calculateaverage(ifstream& input, ofstream& output, double& average)
{
int score, total=0;
for (int count=1, count<=5, count++)
{
input>>score;
count<<setw(10)<<right<<score;
output<<setw(10)<<right<<score;
total += score;
}
average=total/5;
}
char calculategrade (double mean)
{
char grade;
switch (static_cast<int>(mean/10)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
grade='F';
break;
case 6:
grade='D';
break;
case 7:
grade='C';
break;
case 8:
grade='B';
case 9:
case 10:
grade='A';
return grade;
}
}
can some1 please tell me what im doing wrong...i think it has to do with the brackets ({) but im still not sure...all help is greatly appreciated
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(94) : error C2601: 'calculateaverage' : local function definitions are illegal
1> c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(18): this line contains a '{' which has not yet been matched
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(108) : error C2601: 'calculategrade' : local function definitions are illegal
1> c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(18): this line contains a '{' which has not yet been matched
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(134) : error C2958: the left parenthesis '(' found at 'c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(111)' was not matched correctly
1>c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(136) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\orange\my documents\visual studio 2008\projects\new\new\new.cpp(18)' was matched
here is my code:
// new.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using std::cout;
using std::cin;
using std::endl;
using namespace std;
void calculateaverage(ifstream& input, ofstream& output, double& average);
char calculategrade(double mean);
int _tmain(int argc, _TCHAR* argv[])
{
int count=0;
double studentaverage, classaverage, classtotal=0;
char studentgrade;
string studentname;
ifstream infile;
ofstream outfile;
infile.open("scores.txt");
outfile.open("outfile.txt");
cout<<setw(10)<<left<<"Student";
cout<<setw(10)<<left<<"Test 1";
cout<<setw(10)<<left<<"Test 2";
cout<<setw(10)<<left<<"Test 3";
cout<<setw(10)<<left<<"Test 4";
cout<<setw(10)<<left<<"Test 5";
cout<<setw(10)<<left<<"Average";
cout<<setw(10)<<left<<"Grade";
cout<<endl;
outfile<<setw(10)<<left<<"Student";
outfile<<setw(10)<<left<<"Test 1";
outfile<<setw(10)<<left<<"Test 2";
outfile<<setw(10)<<left<<"Test 3";
outfile<<setw(10)<<left<<"Test 4";
outfile<<setw(10)<<left<<"Test 5";
outfile<<setw(10)<<left<<"Average";
outfile<<setw(10)<<left<<"Grade";
cout<<endl;
cout.precision(0);
outfile.precision(0);
cout<<fixed;
outfile<<fixed;
while (!infile.eof())
{
studentaverage=0;
infile>>studentname;
cout<<setw(10)<<left<<studentname;
outfile<<setw(10)<<left<<studentname;
calculateaverage(infile, outfile, studentaverage);
cout<<setw(10)<<right<<studentaverage;
outfile<<setw(10)<<right<<studentaverage;
studentgrade=calculategrade(studentaverage);
cout<<setw(8)<<right<<studentgrade<<endl;
classtotal += studentaverage;
count++;
{
cout<<endl;
outfile<<endl;
cout<<"Class Average";
outfile<<"Class Average";
classaverage=classtotal/count;
cout<<setw(57)<<right<<classaverage;
outfile<<setw(57)<<right<<classaverage;
cout<<setw(8)<<right<<calculategrade(classaverage)<<endl;
outfile<<setw(8)<<right<<calculategrade(classaverage)<<endl;
}
return 0;
}
void calculateaverage(ifstream& input, ofstream& output, double& average)
{
int score, total=0;
for (int count=1, count<=5, count++)
{
input>>score;
count<<setw(10)<<right<<score;
output<<setw(10)<<right<<score;
total += score;
}
average=total/5;
}
char calculategrade (double mean)
{
char grade;
switch (static_cast<int>(mean/10)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
grade='F';
break;
case 6:
grade='D';
break;
case 7:
grade='C';
break;
case 8:
grade='B';
case 9:
case 10:
grade='A';
return grade;
}
}
can some1 please tell me what im doing wrong...i think it has to do with the brackets ({) but im still not sure...all help is greatly appreciated