Hi, I'm hoping someone can help me figure this out. I have to write a program to average scores and print grades using structs and arrays. It's a problem for my class and I think I'm close to finishing but I'm just missing something...maybe a couple of things.
I'm getting this error right now - (33) : error C2275: 'std::ifstream' : illegal use of this type as an expression.
Any hints, tips, or suggestions would be great. Thank you!
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;
int openFile(ifstream &rss, string file, string grades);
void displayHeader();
void readStuData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany);
float getAverage(int scores[], int count);
void assignGrade(int oneScore, float average);
void reportResults(int id[], int scores[], int count);
const int MAX_SIZE = 10;
int main()
{
ifstream rss;
string file;
string grades;
int scores[MAX_SIZE];
int id[MAX_SIZE];
int i , count = 0, oneScore = 0;
float avg = 0, average = 0;
bool tooMany;
cout << "Enter filename: ";
cin >> file;
openFile(ifstream &rss,file,grades);
displayHeader();
readStuData(rss,scores,id,count,tooMany);
getAverage(scores,count);
assignGrade(oneScore,average);
reportResults(id,scores,count);
if (tooMany = true)
{
cout << "Average score is: " << getAverage(scores,count) << "%" << endl;
cout << "The array is filled. Remaining scores will not be stored.";
cout << endl;
}
else
reportResults(id,scores,count);
}
void reportResults(int id[], int scores[], int count)
{
int i;
int oneScore;
float average;
string grades;
for (int i = 0; i < MAX_SIZE; i++)
{
assignGrade(oneScore,average);
cout << id[i] << setw(17) << scores[i] << setw(17) << grades << endl;
}
}
void assignGrade(int oneScore, float average)
{
string grades, file;
ifstream rss;
int scores[MAX_SIZE];
rss >> scores[oneScore];
oneScore = 0;
while (!rss.eof() && oneScore < MAX_SIZE)
{
if (oneScore > average + 10)
{
grades = "OUTSTANDING";
}
else if (oneScore < average - 10)
{
grades = "UNSATISFACTORY";
}
else
{
grades = "SATISFACTORY";
}
oneScore++;
rss >> scores[oneScore];
}
}
float getAverage(int scores[], int count)
{
int id[MAX_SIZE];
int sum = 0;
float average;
int i;
for(int i = 0; i < MAX_SIZE; i++)
{
sum += scores[i];
count++;
}
average = sum / MAX_SIZE;
return average;
}
void displayHeader()
{
//Output header
cout << "\nStudent ID" << setw(13) << "Scores" << setw(13) << "Grades"<< endl;
}
void readStuData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
int tempID;
int tempScore;
//Get input
rss >> tempID >> tempScore;
while(!rss.eof() && (count < MAX_SIZE))
{
id[count] = tempID;
scores[count] = tempScore;
count++;
rss >> tempID >> tempScore;
if (count > MAX_SIZE)
{
tooMany = true;
}
else
tooMany = false;
}
}
int openFile(ifstream &rss, string file)
{
rss.open(file.c_str());
if (rss.fail())
{
cerr << "ERROR: Cannot open file for input." << endl;
return EXIT_FAILURE;
}
}