Code isnt working for some reason

gg
Last edited on
You don't appear to be to be creating or initializing any student objects.
Also you are calling myStudent :: getData() from main() but there does not seem to be a matching implementation. Mind you I'm loosing concentration.
wait what do u mean I'm not initializing any student objects o.O? And getData i think is whats causing my problem but im not sure what it is
Anyone? Its due tomorrow night and Im frustrated because i cant figure it out >.<
it works fine with a name without spaces!
so try to change cin
Last edited on
just change your code as below...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Student::getData()
{
    setSize();
    string name;
    int age;
    for(int i=0; i<numStudents; i++)
    {
	cout<<"Enter age "<<i+1<<": ";
        cin>>age;
        ages[i]=age;
	cin.ignore(sizeof(age),'\n');
	cout<<"Enter name "<<i+1<<" <lastname, firstname>: ";
        getline(cin,name);
        names[i]=name;
    }
}
Last edited on
So the above works but is there a way i can get the names to be asked first and then the age? I used your code to just test it out, but once i get to my last person, The .exe crashes. If i use one person at the beginning, the results come up, but give me a weird list of numbers o.O?
by using cin.ignore();

try this one instead...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Student::getData()
{
    setSize();
    string name;
    int age;
    for(int i=0; i<numStudents; i++)
    {
        cout<<"Enter name "<<i+1<<" <lastname, firstname>: ";
	cin.ignore();
        getline(cin,name);		
	names[i]=name;
        cout<<"Enter age "<<i+1<<": ";
        cin>>age;
        ages[i]=age;
    }
}
Last edited on
Perfect :D Now if only the results worked. Not sure the error because the .EXE just crashes after i enter in the last age for the person =/ (Testing just 6 people)
Hrmmm I think its either my sort arrays or display arrays. Stupid ExE just keeps crashing I cant tell whats wrong. Anyone know why it crashes?
Topic archived. No new replies allowed.