Struct not declared problem

The program debugger says that 'student' was no declared in this scope.
The coding program i use is CodeBlocks.

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
70
71
72
73
74
75
  
#include<iostream>
#include<vector>
using namespace std;

struct StudentType{
    string last;
    string first;
    int Class;
};
//--------------------------------------------------------------
void GetStudentData(StudentType &student)
{
    cout<<"Enter last name: ";cin>>student.last;
    cout<<"Enter first name: ";cin>>student.first;
    cout<<"Enter class: ";cin>>student.Class;
}
//--------------------------------------------------------------
void DisplayStudentData(const StudentType &student)
{
    cout<<student.first<<" "<<student.last<<" "<<student.Class<<endl;
}
//---------------------------------------------------------------
struct SchoolType{
    SchoolType();
    const int sizechange;
    int numstudent;
    vector<StudentType>student;
};
//--------------------------------------------------------------
SchoolType::SchoolType()
    :sizechange(10),student(10),numstudent(0)
{
}
//-----------------------------------------------------------
void DisplaySchool(const SchoolType &school)
{
    for(int i=0;i<school.numstudent;i++)
        DisplayStudentData(school,student[i]);
}
//--------------------------------------------------------------
void AddStudent(SchoolType &school,const StudentType &newstudent)
{
    if(school.numstudent==school.student.size())
        school.student.resize(school.numstudent+school.sizechange);
    school.student[school.numstudent] = newstudent;
    school.numstudent++;
}
//-------------------------------------------------------------------
int main()
{
    StudentType student;
    SchoolType school;

    bool quit = false;
    do{
        cout<<"Press choice to Add, Display, Quit: ";
        char choice;
        cin>>choice;
        cout<<endl;
        switch(choice){
            case 'A':
            case 'a': GetStudentData(student);
                      AddStudent(school,student);
                      break;
            case 'D':
            case 'd': DisplaySchool(school);
                      break;
            case 'q':
            case 'Q': quit = true; break;
        }
    }while(quit);
    return 0;
}
Where did you declare student?
Finger trouble :-)

in line 39 you used a comma "," instead of a full stop "."

Change:DisplayStudentData(school,student[i]);
To:DisplayStudentData(school.student[i]);

In case full stops are a valuable resource in your neigbourhood, I've included several - feel free to request more if you run out anytime.

"................................................................................................................................................"

It's been a long day, I usually make better jokes than this :-(
+1 for tipaye
oh, yeah
thank man
Topic archived. No new replies allowed.