I am unsure why I am getting unable to resolve identifier error
Jul 8, 2012 at 7:27am UTC
I've started a new project where I have to read id numbers and grades from a file, and place information in a array of a struct. I am pretty sure I do not have to declare
i
and
j
in my
for
statements as variables, but netbeans keeps giving me unable to resolve identifier errors for those variables. Any suggestions would help, here's my code so far.
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
#include<iostream>
#include<fstream>
#include<iomanip>
const int MAX_ID = 10; // max number of ids
const int MAX_SCORES = 7; // max number of scores
using namespace std;
struct grades
{
int id[MAX_ID]; //array for id
int scores[MAX_SCORES]; //array for scores
float stu_avg; // student average score
string grade; // student grade
};
#define in_grades "grades.txt" // defining local file grades.txt
//function prototype
void process_ngrades (ifstream&);
int main()
{
ifstream ngrades; // ngrades input stream
ngrades.open(in_grades); //open file
//if ifstream doesn't open
if (ngrades.fail())
{
cerr << "*** Cannot Open for input." << endl;
return EXIT_FAILURE;
}
process_ngrades (ngrades);
}
void process_ngrades (ifstream& ngrades)
{
int stu_score=0; //sum of student scores
int tot_score=0; //total score for all students
int tot_count=0; // count for scores
float stu_avg;
string grade; //grade for student score
while (!ngrades.eof())
{
for (i = 0, i < MAX_ID, i++)
{
ngrades>> grades.id[i];
for (j=0, j<MAX_SCORES, j++)
{
ngrades >> grades.scores[j];
stu_score += grades.scores;
tot_count ++
}
grades.stu_avg= stu_score / MAX_SCORES;
tot_score+= stu_score;
stu_score = 0;
}
}
}
Jul 8, 2012 at 7:50am UTC
Why are you sure that "you do not have to declare i and j in your for statements as variables"?!
Each name used in a program shall be declared.
So you shall write
for ( int i = 0, i < MAX_ID, i++)
Jul 8, 2012 at 2:31pm UTC
What vlad said, except you need semi-colons
for (int i = 0; i < MAX_ID; i++)
Jul 8, 2012 at 4:51pm UTC
It was late please forgive me hahaha, no data type, or semi-colons, i couldn't figure it out for nothing between my nods.
Topic archived. No new replies allowed.