May 20, 2010 at 4:15am UTC
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
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
void getstudents();
struct stinfo
{
char student_name[20];
int student_ID;
int program_grades[15];
int quiz_grades[12];
int exam_grades[3];
int final_exam;
float prav;
float quav;
float exav;
float final_score;
char final_grade;
};
int main()
{
int student_number;
ifstream fin;
fin.open("studentdata.txt" );
fin >> student_number;
cout << "There are " << student_number << " students in this class.\n\n"
<< "Student\t\tStudent\tProg\tQuiz\tExam\tFinal\tFinal\tFinal\n"
<< "Name \t\tID \tAvg \tAvg \tAvg \tExam \tScore\tGrade\n"
<< "---------------------------------------------------------------------\n" ;
stinfo students[6];
for (int i=0; i < 6; i++)
{
getline(fin, stinfo[i].student_name); //I get an error here saying
}
//"expected primary-expression before '[' token
system ("pause" );
}
Last edited on May 20, 2010 at 5:29am UTC
May 20, 2010 at 5:01am UTC
There is no stinfo[] object. stinfo for all practical purposes is a type.
-Albatross
May 20, 2010 at 5:06am UTC
Aw man do you think you can explain how I can stick the info from my text file into those variables in the structure? I have been trying all day and cannot figure it out!
Last edited on May 20, 2010 at 5:07am UTC
May 20, 2010 at 5:10am UTC
Replace the stinfo in that line with students
, which you declared earlier.
Oh, and do consider using strings in place of char[]s.
-Albatross
Last edited on May 20, 2010 at 5:12am UTC
May 20, 2010 at 5:19am UTC
1 2 3 4 5
stinfo students[6];
for (int i=0; i < 6; i++)
{
getline(fin, students[i].student_name);
}
Ok I changed that part to this but I am receiving another error now.
I am using dev c++ if it matters.
It says, no matching function for call to `getline(std::ifstream&, char[20])'
Last edited on May 20, 2010 at 5:27am UTC
May 20, 2010 at 5:29am UTC
That is because getline() takes an std::string as the second parameter, not a char array.
May 20, 2010 at 5:36am UTC
Ok I tried
typedef basic_string<char> student_name;
and then I get, invalid use of `stinfo::student_name'
Dang I have never used this sort of string command before I am not sure if I am doing it wrong.
This assignment is so we learn to use structures so I have never done it before and it's confusing me since I have to read from a .txt file. I cannot get it to work that's all I want to do is stick these inputs into those structure variables.
There's exactly enough grades to fit.
Bowles,Bill
123456
6
2
5
5
5
3
5
6
0
4
6
6
2
5
5
19
18
19
12
17
15
19
18
19
12
17
15
87
85
91
120
Last edited on May 20, 2010 at 5:41am UTC
May 20, 2010 at 5:49am UTC
Nice!!!!! I got no error!!!!!
Now how can I cout student_name to display the persons name?
cout student_name is undeclared.
Thanks for all the help I will check out the link also.