Program written with one type of error messge (but 17 of them!)

This is a discussion on Program written with one type of error messge (but 17 of them!) within the C++ Programming forums, part of the General Programming Boards category; Hello, I have one type of error message that I can't figure out. I'm using Visual C++ to compile my ...

  1. #1
    logic_dummy
    Guest

    Question Program written with one type of error messge (but 17 of them!)

    Hello,

    I have one type of error message that I can't figure out. I'm using Visual C++ to compile my code. Error Message: error C2228: left of '.code' must have class/struct/union type.

    This error appears 17 times in each instance I have a member of my struct in a part of my program (i.e. code, hours, gpa). The requirements for this program are as follows..

    Find the average and highest number of hours completed, lowest and highest GPA, the associated codes for each as well as the number of students with passing GPA (2.0 or better) in a class of not more than 20 students. After all input is entered the student IDs Hours, and GPA must be output for each student. The ID and GPA of each student exceeding the average GPA must be output along with highest and lowest GPA and associated IDs.. The students are identified by a three digit code between 100 and 999.

    Constraints: A Struct must be used and instantiated by an array. Student IDs and GPAs are input from a data file. Hours and names must be input from the screen. No Global varables may be used. A function must exist to determine the highest and lowest GPAs and associated codes.

    I'm thinking I may be having problems not only with my structure, but with my file use as well. Any help would be much appreciated!! Hopefully I'm not over my limit on characters here...THANKS :-)

    #include <iostream.h>
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <math.h>

    const int smax = 21;
    const int tsize = 3;
    const int nsize = 20; //check

    struct STU
    {
    char name[30]; //check
    int code;
    double hours;
    double gpa;
    } ;

    int stu_info(STU [] [tsize]);
    void stats_hours(STU [] [tsize], int);
    double stats_gpa(STU [] [tsize], int);
    void best_stus(STU [] [tsize], int, double);

    int main(void)
    {
    STU student[smax] [tsize];

    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);

    int stucount;
    double avg_gpa;

    stucount = stu_info(student);
    stats_hours(student, stucount);
    avg_gpa = stats_gpa(student, stucount);
    best_stus(student, stucount, avg_gpa);

    return 0;
    }

    int stu_info(STU student[] [tsize])
    {

    ifstream file1, file2;
    char file1_disk[nsize] = "student.dat";
    char file2_disk[nsize] = "stuname.dat";

    int stucount;
    stucount = 0;

    file1.open (file1_disk);

    if (file1.fail())
    {
    cout << file1_disk << " is not available";
    exit(1);
    }

    file2.open (file2_disk);
    if (file2.fail())
    {
    cout << file2_disk << " is not available";
    exit(1);
    }

    do
    {
    if (stucount < 20)
    {
    cout << "Enter Student Code (100-999): ";
    cin >> student.code; //FIRST ERROR
    if (( student.code > -1 && student.code < 100) || (student.code > 999))
    {
    cout << "\n\nCODE MUST BE 100-999!";
    }
    else if (student.code > -1)
    {
    for (int k = 0; k < smax; ++k)
    {
    file1 >> student[k].code >> student[k].gpa;
    file2.getline (student[k].name, nsize);
    file2 >> ws;

    }

    file1.close();
    file2.close();

    cout <<"\n\tEnter Hours Completed: ";
    cin >> student.hours;
    cout << "\n\tCurrent G.P.A: ";
    cin >> stud.gpa;
    student [stucount] [0] = student.code;
    student [stucount] [1] = student.hour;
    student [stucount] [2] = student.gpa;
    ++stucount;

    }

    }
    else
    {
    cout <<"\n\nMAXIMUM CLASS SIZE IS 20!!";
    student.code -1;
    }
    while (student.code > -1);
    return stucount;

    }
    void stats_hours(STU student [] [tsize], int count)
    {
    double tot, avg, hihour;
    int x, y;
    tot = 0;
    hihour = 0;

    for (x = 0; x < count; ++x)
    {
    tot = tot + student [x] [1];
    if (student [x] [1] > hihour)
    {
    hihour = student [x] [1];
    }
    }
    avg = tot / count;
    cout << "\n\n\nThe Average Numbers of Hours for this Class is: "
    << avg;

    for (y = 0; y < count; ++y)
    {
    if (student [y] [1] == hihour)
    {
    cout << "\nStudent " << student [y] [0]
    << " has the highest number of hours completed: "
    << student [y] [1] << " hours";
    }
    }
    return;



    }

    double stats_gpa(STU student [] [tsize], int count)
    {
    int x, y;
    double higpa, logpa, tot, avg;
    int passcount;
    higpa = tot = 0;
    passcount = 0;
    logpa = 5.0;
    for (x = 0; x < count; ++x)
    {
    if (student [x] [2] > higpa)
    {
    higpa = student [x] [2] < logpa)
    }
    if (student [x] [2] >= 2.0)
    {

    ++passcount;
    }
    tot = tot + student[x] [2];
    }
    cout << "\n\n";
    for (y =0; y < count; ++y)
    {
    if (student [y] [2] == higpa)
    {
    cout << "\nStudent " << student [y] [0]
    << " had the highest GPA of: "
    << student [y] [2];
    }
    }
    for (y=0; y < count; ++y)
    {
    if (sturay [y] [2] == logpa)
    {
    cout << "\nStudent " << sturay [y] [0]
    << " had the lowest GPA of: "
    << sturay [y] [2];
    }
    }
    cout << "\n";
    cout << passcount << " students are passing(GPA of 2.0 or higher)";
    avg = tot / count;

    return avg;
    }

    void best_stus(STU student [] [tsize], int count, double avg_gpa)
    {
    int i;
    cout << "\n\n\n";
    for (i=0; i < count; ++i)
    {
    if (student [i] [2] > avg_gpa)
    {
    cout << "Student " << student [i] [0]
    << " Exceeded the average GPA of "
    << avg_gpa << ", with a GPA of "
    << student [i] [2] << "\n";
    }
    }
    return;

    }

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You defined student as a two-dimensional array of STU's, so so access/modify one of the students you'll have to do -

    student[0][0].code;

    Where student[0][0] is the one you're accessing.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. which data type in image program?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 06-14-2008, 05:17 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  5. C- Program which is to be written?
    By sonusden in forum C Programming
    Replies: 2
    Last Post: 02-01-2002, 10:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21