Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,067 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,582 people online right now. Registration is fast and FREE... Join Now!




syntax error : missing ';' before '<class-head>'

 
Reply to this topicStart new topic

syntax error : missing ';' before '<class-head>', i dont knw why i am gettign this problem

njkiller07
21 Apr, 2008 - 11:23 AM
Post #1

New D.I.C Head
*

Joined: 24 Mar, 2008
Posts: 10

my assignment is to

write a program that will keep track of student information stored in a array(static or dynamic)
5 students or 6 students

described by s struct( student first name, student last name ( both either c string or from the string class) current GPA, and the final exam letter grade (character)

task 1 - computes average gpa for all students in the array as well as the most frequent exam letter grade



so i made a program

CODE
#include <iostream>
#include <string>
using namespace std;
int main()


struct typestudent
{
    string firstname;
    string lastname;
    double gpa;
    char frequentgrade;
};

typestudent s[5];
int a=0,b=0,c=0,d=0,f=0;
    for (int i=0; i<5; i++)
    {
    cout<<"Please enter a student's name."<<endl;
    cin>>s[i] first name;
    cout<<"Please enter a student's name."<<endl;
    cin>>s[i] last name;
    cout<<"Please enter a student's GPA."<<end1;
    cin>>s[i]GPA;
    cout<<"Please enter a student's final exam grade."<<endl;
    cin>>s[i]final;
    
    if(final='a')
        a++;        
    else if (final='b')
        b++;                
    else if (final='c')
        c++;    
    else if (final='d')
        d++;
    else if (final='f')
        f++;
    
    }

    return 0;
}
        



but im getting this messages

C:\Documents and Settings\pp36\Desktop\structures\structures.cpp(13) : error C2143: syntax error : missing ';' before '<class-head>'
C:\Documents and Settings\pp36\Desktop\structures\structures.cpp(13) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

structures.exe - 2 error(s), 0 warning(s)

Mod Edit: changed quote tags to code tags: code.gif
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Syntax Error : Missing ';' Before '<class-head>'
21 Apr, 2008 - 11:40 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
well you program has a int main() at the begining... It seem to me this is out of place. Generally this would go right after your struct, and right before you declare the variable s[], and it would be followed by a '{'.
User is offlineProfile CardPM
+Quote Post

njkiller07
RE: Syntax Error : Missing ';' Before '<class-head>'
21 Apr, 2008 - 11:47 AM
Post #3

New D.I.C Head
*

Joined: 24 Mar, 2008
Posts: 10

i tried it man it still doesnt work

i still dont knw wat the problem is
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Syntax Error : Missing ';' Before '<class-head>'
21 Apr, 2008 - 11:58 AM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
post the new code with the fix and any new errors
User is offlineProfile CardPM
+Quote Post

njkiller07
RE: Syntax Error : Missing ';' Before '<class-head>'
21 Apr, 2008 - 12:13 PM
Post #5

New D.I.C Head
*

Joined: 24 Mar, 2008
Posts: 10

CODE
// By Pragnesh Patel
// Professor John Ryan
// 4/21/08
// Structures

#include <iostream>
#include <string>
using namespace std;



struct typestudent
{
    string firstname;
    string lastname;
    double gpa;
    char frequentgrade;
};
    int main()
    {

    typestudent s[5];
    int a=0,b=0,c=0,d=0,f=0;
    for (int i=0; i<5; i++)
    {
    cout<<"Please enter a student's name."<<endl;
    cin>>s[i] first name;
    cout<<"Please enter a student's name."<<endl;
    cin>>s[i] last name;
    cout<<"Please enter a student's GPA."<<end1;
    cin>>s[i]GPA;
    cout<<"Please enter a student's final exam grade."<<endl;
    cin>>s[i]final;
    
    if(final=='a')
        a++;        
    else if (final=='b')
        b++;                
    else if (final=='c')
        c++;    
    else if (final=='d')
        d++;
    else if (final=='f')
        f++;
    
    }

    return 0;
}
        
    


C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(27) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'struct typestudent' (or there is no acceptable conversion)
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(27) : error C2146: syntax error : missing ';' before identifier 'first'
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(27) : error C2065: 'first' : undeclared identifier
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(27) : error C2146: syntax error : missing ';' before identifier 'name'
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(27) : error C2065: 'name' : undeclared identifier
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(29) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'struct typestudent' (or there is no acceptable conversion)
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(29) : error C2146: syntax error : missing ';' before identifier 'last'
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(29) : error C2065: 'last' : undeclared identifier
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(29) : error C2146: syntax error : missing ';' before identifier 'name'
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(30) : error C2065: 'end1' : undeclared identifier
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(31) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'struct typestudent' (or there is no acceptable conversion)
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(31) : error C2146: syntax error : missing ';' before identifier 'GPA'
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(31) : error C2065: 'GPA' : undeclared identifier
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(33) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'struct typestudent' (or there is no acceptable conversion)
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(33) : error C2146: syntax error : missing ';' before identifier 'final'
C:\Documents and Settings\pp36.ACADEMIC.000\Desktop\structures2\structures2.cpp(33) : error C2065: 'final' : undeclared identifier
Error executing cl.exe.

structures2.exe - 16 error(s), 0 warning(s)
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Syntax Error : Missing ';' Before '<class-head>'
21 Apr, 2008 - 12:17 PM
Post #6

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
I fixed all the errors and commented where they were wrong. Here is the final code: (it compiles fine, but I haven't tested it)
CODE

#include <iostream>
#include <string>
using namespace std;

struct typestudent
{
    string firstname;
    string lastname;
    double gpa;
    char final; //frequency wasn't actually used, so i replaced it with what you was using
};

int main() // comes after your struct
{ // main function needs the opening symbol to contain everything
typestudent s[5];
int a=0,b=0,c=0,d=0,f=0;
    for (int i=0; i<5; i++)
    {
    cout<<"Please enter a student's name."<<endl;
    cin>>s[i].firstname; // you need a . not spaces
    cout<<"Please enter a student's name."<<endl; endl (L) not end1 (1)
    cin>>s[i].lastname; // you need a . not spaces
    cout<<"Please enter a student's GPA."<<endl;
    cin>>s[i].gpa; // you need a . not spaces
    cout<<"Please enter a student's final exam grade."<<endl;
    cin>>s[i].final; // you need a . not spaces

    if(s[i].final='a') // final of the current member of array
        a++;
    else if (s[i].final='b') // final of the current member of array
        b++;
    else if (s[i].final='c') // final of the current member of array
        c++;
    else if (s[i].final='d') // final of the current member of array
        d++;
    else if (s[i].final='f') // final of the current member of array
        f++;

    }
    system("pause"); // pauses for user to see output
    return 0;
}


Hope this helps smile.gif

This post has been edited by gabehabe: 21 Apr, 2008 - 12:19 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:50PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month