Thread: Arrays in structures

  1. #1
    Unregistered
    Guest

    Unhappy Arrays in structures

    I am new to C++, obviously, and I have to write a program for a class. The program should be very simple. it asks to make a structure for a Student that includes the students name and a 2x3 array that represents two semesters with three grades each. Please don't fall down laughing when you see my code. Here are my problems. First the nested loop crashes and second I don't think I am correctly formating my cin.getline statments correctly either. Help!!!

    void main(void)
    {
    int Cnt,
    d,
    e;

    do{
    for (Cnt = 0; Cnt <= 4; Cnt++)
    {
    cout << "Please enter the Students Name: ";
    cin.getline(Student[Cnt].Name, 29);
    if (Student[Cnt].Name == '\0')
    break;

    for(d = 0; d < 1; d++)
    {
    cout << "Please enter students grades for semester " << (d + 1);
    cin >> Student[Cnt].Grade[d][e];
    for(e = 0; e < 2; e++)
    {
    cout << "Grade #" << e << endl;
    cin >> Student[Cnt].Grade[d][e];
    }
    }
    }
    }
    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    39

    Red face

    well u havent make a structure of that students and grade variables
    once a kohatian,always a kohatian!

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    4

    The Structure

    I didn't copy and paste the structure so here is what I have

    struct Record
    {
    char Name[30];
    int Grade[2][3];
    }Student[30]

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Does this even compile?

  5. #5
    Unregistered
    Guest
    structs need a ; at the end -

    struct myStruct
    {
    blah
    blah
    blah
    };

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > do{

    Where's the other end of the loop?

    > void main(void)

    No. int main(void)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-09-2009, 11:06 AM
  2. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  3. errors with arrays and structures
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 11:48 PM
  4. Newbie Help (Arrays, Structures, Functions,Pointers)
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 06:29 PM
  5. Replies: 7
    Last Post: 12-29-2001, 11:25 PM