unexpected end of file found!

dunno what's the problem in the end of the code!

Page 1 of 1

6 Replies - 2180 Views - Last Post: 15 May 2009 - 04:15 PM Rate Topic: -----

#1 chubzyko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 28-August 08

unexpected end of file found!

Posted 15 May 2009 - 06:51 AM

can somebody help me figure out what's the missing code or incorrect code in my program? this is just an example for me to start a new program, but i cant start to make a new program because i cant make the sample program work.

#include<string>
#include<iostream>
using namespace std;
void clear();
int menu();

class teacher

{

public:

	void info(char name[], char id[], int age, char address[], char gender[])

{

	strcpy(m_name, name);
	strcpy(m_id, id);
	m_age=age;
	strcpy(m_address, address);
	strcpy(m_gender, gender);

}

	void contract(int hours, double salary)

{

	m_hours=hours;
	m_salary=salary;
	m_contract=m_hours*m_salary;

	void profession(char majorsubject[], char subject[])
{

	strcpy(m_majorsubject, majorsubject);
	strcpy(m_subject, subject);

}
	void display()

{

	clear();

	cout<<"		*personal info*\n------------"<<endl;
	cout<<"	name:	"<<m_name<<endl;
	cout<<"	id:		"<<m_id<<endl;
	cout<<"	age:	"<<m_age<<endl;
	cout<<"	address:	"<<m_address<<endl;
	cout<<"	gender:	"<<m_gender<<endl;
	cout<<"		*salary*\n-------------"<<endl;
	cout<<"		*profession*\n-------------"<<endl;
	cout<<"majorsubject:	"<<m_majorsubject<<endl;
	cout<<"subject:	"<<m_subject<<endl;

}

private:
	char m_name[50], m_majorsubject[20], m_subject[20], m_address[50], m_gender[10], m_id[8]; int m_age, m_hours; 
	double m_salary, m_contract;

};

void main()

{
	char name1[20], major[20], subject[20], address[50], gender1[10], id1[8];

	int age1, hours1, mc; 
	
	double salary1;
	teacher myteacher;
	mc=0;
	while(mc!=5)

{

	mc=menu();
	switch(mc)

{

case 1:

	clear();
	cout<<"		personal info\n------------"<<endl;
	cout<<"enter name:";
	cin>>name1;
	cout<<"enter id:";
	cin>>id1;
	cout<<"enter age:";
	cin>>age1;
	cout<<"enter gender:";
	cin>>gender1;
	myteacher.info(name1, id1, age1, address1, gender1);
	break;

case 2:

	clear();
	cout<<"		salary\n------------"<<endl;
	cout<<"no. of hours worked:";
	cin>>hours1;
	cout<<"hourly rate:";
	cin>>salary1;
	break;


case 3:

	clear();
	cout<<"		position\n-----------"<<endl;
	cout<<"enter major subject:";
	cin>>major1;
	cout<<"enter subject:";
	cin>>subject1;
	myteacher.profession(major1, subject1);
	break;

case 4:

	myteacher.display();
	break;

case 5:

	break;
}
}
}
void clear()

{

	cout<<"\n\n\n\n\n\n\n\n\n"<<endl;

}

int menu()


{
	int mc1;

	cout<<"1. personal info"<<endl;
	cout<<"2. salary"<<endl;
	cout<<"3. profession"<<endl;
	cout<<"4. display"<<endl;
	cout<<"5. exit"<<endl;
	cin>>mc1;
	return(mc1);
}


This post has been edited by chubzyko: 15 May 2009 - 06:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: unexpected end of file found!

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: unexpected end of file found!

Posted 15 May 2009 - 06:56 AM

Welcome to DIC!

Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings?
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details.
Was This Post Helpful? 0
  • +
  • -

#3 chubzyko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 28-August 08

Re: unexpected end of file found!

Posted 15 May 2009 - 07:00 AM

View Postjanotte, on 15 May, 2009 - 05:56 AM, said:

Welcome to DIC!

Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings?
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details.




thnks for the quick response! anyway, yeah i can compile the code and build. but if im going to hit the execute program button, here's the message the show up

"Compiling...
Cpp1.cpp
C:\Documents and Settings\marvie\Desktop\c++\Cpp1.cpp(154) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Cpp1.exe - 1 error(s), 0 warning(s)"
Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: unexpected end of file found!

Posted 15 May 2009 - 07:27 AM

The formatting of the code you posted was disgusting.

Was that provided to you by a teacher in that format?
A very bad example.
Don't follow it and if you get anymore like that the first thing to do is lay it out so you can read it.

Having done some formatting and moving a few things about so it had a chance to compile I discovered a missing closing brace "}" at what is line 37 in my code.

I fixed that and now here are the compile errors you need to deal with:
------------
DIC.cpp:60: error: ‘::main’ must return ‘int’
DIC.cpp: In function ‘int main()’:
DIC.cpp:92: error: ‘address1’ was not declared in this scope
DIC.cpp:108: error: ‘major1’ was not declared in this scope
DIC.cpp:110: error: ‘subject1’ was not declared in this scope
DIC.cpp:111: error: no matching function for call to ‘teacher::profession(<type error>, <type error>)’
DIC.cpp:39: note: candidates are: void teacher::profession(char*, char*)
DIC.cpp:62: warning: unused variable ‘major’
DIC.cpp:63: warning: unused variable ‘subject’
DIC.cpp:64: warning: unused variable ‘address’
------------

Here's my formatted version of your code.
/*  1 */ #include <string>
/*  2 */ #include <iostream>
/*  3 */ using namespace std;
/*  4 */ void clear();
/*  5 */ int menu();
/*  6 */ 
/*  7 */ class teacher {
/*  8 */    private:
/*  9 */        char    m_name[50],
/* 10 */                m_majorsubject[20],
/* 11 */                m_subject[20],
/* 12 */                m_address[50],
/* 13 */                m_gender[10],
/* 14 */                m_id[8];
/* 15 */                
/* 16 */        int     m_age,
/* 17 */                m_hours;
/* 18 */                
/* 19 */        double  m_salary,
/* 20 */                m_contract;
/* 21 */ 
/* 22 */    public:
/* 23 */        
/* 24 */        void info(char name[], char id[], int age, char address[], 
/* 25 */                    char gender[]) {
/* 26 */            strcpy(m_name, name);
/* 27 */            strcpy(m_id, id);
/* 28 */            m_age=age;
/* 29 */            strcpy(m_address, address);
/* 30 */            strcpy(m_gender, gender);
/* 31 */        }
/* 32 */ 
/* 33 */        void contract(int hours, double salary) {
/* 34 */            m_hours=hours;
/* 35 */            m_salary=salary;
/* 36 */            m_contract=m_hours*m_salary;
/* 37 */        }
/* 38 */ 
/* 39 */        void profession(char majorsubject[], char subject[]) {
/* 40 */            strcpy(m_majorsubject, majorsubject);
/* 41 */            strcpy(m_subject, subject);
/* 42 */        }
/* 43 */        
/* 44 */        void display() {
/* 45 */            clear();
/* 46 */            
/* 47 */            cout << "        *personal info*\n------------" << endl;
/* 48 */            cout << "    name:    " << m_name << endl;
/* 49 */            cout << "    id:        " << m_id << endl;
/* 50 */            cout << "    age:    " << m_age << endl;
/* 51 */            cout << "    address:    " << m_address << endl;
/* 52 */            cout << "    gender:    " << m_gender << endl;
/* 53 */            cout << "        *salary*\n-------------" << endl;
/* 54 */            cout << "        *profession*\n-------------" << endl;
/* 55 */            cout << "majorsubject:    " << m_majorsubject << endl;
/* 56 */            cout << "subject:    " << m_subject << endl;
/* 57 */        }
/* 58 */ };
/* 59 */ 
/* 60 */ void main() {
/* 61 */    char    name1[20],
/* 62 */            major[20], 
/* 63 */            subject[20], 
/* 64 */            address[50], 
/* 65 */            gender1[10], 
/* 66 */            id1[8];
/* 67 */    
/* 68 */    int     age1, 
/* 69 */            hours1, 
/* 70 */            mc;
/* 71 */             
/* 72 */    double  salary1;
/* 73 */ 
/* 74 */    teacher myteacher;
/* 75 */    mc=0;
/* 76 */    
/* 77 */    while(mc!=5) {
/* 78 */        mc=menu();
/* 79 */        
/* 80 */        switch(mc) {
/* 81 */            case 1:
/* 82 */                clear();
/* 83 */                cout << "        personal info\n------------" << endl;
/* 84 */                cout << "enter name:";
/* 85 */                cin >> name1;
/* 86 */                cout << "enter id:";
/* 87 */                cin >> id1;
/* 88 */                cout << "enter age:";
/* 89 */                cin >> age1;
/* 90 */                cout << "enter gender:";
/* 91 */                cin >> gender1;
/* 92 */                myteacher.info(name1, id1, age1, address1, gender1);
/* 93 */                break;
/* 94 */ 
/* 95 */            case 2:
/* 96 */                clear();
/* 97 */                cout << "        salary\n------------" << endl;
/* 98 */                cout << "no. of hours worked:";
/* 99 */                cin >> hours1;
/*100 */                cout << "hourly rate:";
/*101 */                cin >> salary1;
/*102 */                break;
/*103 */ 
/*104 */            case 3:
/*105 */                clear();
/*106 */                cout << "        position\n-----------" << endl;
/*107 */                cout << "enter major subject:";
/*108 */                cin >> major1;
/*109 */                cout << "enter subject:";
/*110 */                cin >> subject1;
/*111 */                myteacher.profession(major1, subject1);
/*112 */                break;
/*113 */ 
/*114 */            case 4:
/*115 */                myteacher.display();
/*116 */                break;
/*117 */ 
/*118 */            case 5:
/*119 */                break;
/*120 */        }
/*121 */    }
/*122 */ }
/*123 */ 
/*124 */ void clear() {
/*125 */    cout << "\n\n\n\n\n\n\n\n\n" << endl;
/*126 */ }
/*127 */ 
/*128 */ int menu() {
/*129 */    int mc1;
/*130 */ 
/*131 */    cout << "1. personal info" << endl;
/*132 */    cout << "2. salary" << endl;
/*133 */    cout << "3. profession" << endl;
/*134 */    cout << "4. display" << endl;
/*135 */    cout << "5. exit" << endl;
/*136 */    cin >> mc1;
/*137 */    
/*138 */    return(mc1);
/*139 */ }


This post has been edited by janotte: 15 May 2009 - 07:31 AM

Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: unexpected end of file found!

Posted 15 May 2009 - 08:46 AM

Unexpected end of file normally means that there is a mismatch of brackets or quotation marks. Generally most IDE's have tools to help you discover which it is.

Take a look at the function "contract" which does not have a closing }

Although I don't really approve of the tone of the previous post, the concept is valid: Clean code makes it easy to find these errors. Use intention to help determine brace matching (open a brace increase indention, close a brace decrease indention).

Not sure that the "line numbers" in the above code are very useful (actually I think that is awful... I would HATE to have to maintain such code).
Was This Post Helpful? 0
  • +
  • -

#6 chubzyko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 28-August 08

Re: unexpected end of file found!

Posted 15 May 2009 - 09:36 AM

hehehe! reading your comments about your comments from other people makes me laugh out loud.

especially this quote
"The formatting of the code you posted was disgusting.

Was that provided to you by a teacher in that format?
A very bad example.
Don't follow it and if you get anymore like that the first thing to do is lay it out so you can read it."

hahahaha! that really made me laugh when I first read it!

anyway, thanks for the help guys! im starting to continue the sample program now and add some functions too. Thanks Janotte!

This post has been edited by chubzyko: 15 May 2009 - 09:36 AM

Was This Post Helpful? 0
  • +
  • -

#7 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: unexpected end of file found!

Posted 15 May 2009 - 04:15 PM

View PostNickDMax, on 15 May, 2009 - 07:46 AM, said:

Not sure that the "line numbers" in the above code are very useful (actually I think that is awful... I would HATE to have to maintain such code).


Just to clarify.
NickDMax is right about the line numbers being ugly.

The line numbers are there only so you can match the errors I provided to the line in the code that I provided.
In the highly unlikely event (IMO) that you thought I was suggesting that they stay in your 'real' code then let's be clear.
Line numbers do not belong in 'real' code..

If you did think I was suggesting you add them to your code then I'm sorry for the confusion.


BTW
I am highly surprised that NickDMax would honestly think anyone would suggest that code would be written and maintained with a column of line numbers as presented in that post. However, what I think may really be going on is that your thread has been made part of something else that it is now clear is going on. That's unfortunate and I am sorry that it has happened to you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1