Thread: Need Help: end of file found before....

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    31

    Need Help: end of file found before....

    I am getting an error in my debugging that i dont understand. I dont even know how to end code yet...I'm 2 days into learning C++ so im not even sure the last section is correct yet.


    This is the debug output.
    Code:
     1>c:\users\****\documents\visual studio 2008\projects\char\char\char.cpp(143) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\****\documents\visual studio 2008\projects\char\char\char.cpp(11)' was matched
    I think the error refers to the section of code that looks like
    Code:
    	if (cPoints > 0)
    Towards the bottom.

    Here is my code.
    Code:
     // Char.cpp : Defines the entry point for the cConsole application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <ctime>
    #include <string>
    using namespace std;
    
    int main()
    {
        string cName;
    	int cLeftOver;
        int cStr;
        int cIntel;
        int cAgi;
        int cCon;
        int cSpe;
    	int cNin;
        int cPoints;
    	
    	
    	cStr = 0;
    	cIntel = 0;
    	cAgi = 0;
    	cCon = 0;
    	cSpe = 0;
    	cNin = 0;
    
        cPoints = 100;
        cout << "It's time to name your character! Please type your characters name: ";
        getline(cin, cName);
        cout << "Welcome to the game " << cName << "!" << endl << "You have 100 Character points to spend." << endl << "These points will be applied to your characters attributes. Lets begin!" << endl << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    	cout << "---------------------------------" << endl << endl;
    
    	cout << "Strength is the attribute that applies to how much damage your mutant does." << endl << "How much strength would you like? (1-25)" << endl;
        cin >> cStr;
        if (cStr > 25)
        {   
            cout << "You're trying to set your Strength too high. Please choose between 1 and 25." << endl;
            cin >> cStr;
        }
    	cPoints = cPoints - cStr;
    	cout << endl << "You have " << cPoints << " points left!" << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    	cout << "---------------------------------" << endl << endl;
    	
    	cout << "Intelligence effects your ability to learn new skills and become stronger at those skills." << endl << "How much intelligence would you like? (1-25)" << endl;
    	cin >> cIntel;
    	if (cIntel > 25)
        {   
            cout << "You're trying to set your intelligence too high...which isnt very intelligent! Please choose between 1 and 25." << endl;
            cin >> cIntel;
        }  
    	cPoints = cPoints - cIntel;
    	cout << endl << "You have " << cPoints << " points left!" << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    	cout << "---------------------------------" << endl << endl;
    
    	cout << "Agility affects how well your character can land attacks." << endl << "How much agility would you like? (1-25)" << endl;
    	cin >> cAgi;
    	if (cAgi > 25)
        {   
            cout << "You're trying to set your agility too high! Please choose between 1 and 25." << endl;
            cin >> cAgi;
        }   
    	cPoints = cPoints - cAgi;
    	cout << endl << "You have " << cPoints << " points left!" << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    	cout << "---------------------------------" << endl << endl;
    	
    	cout << "Constitution is what determines your HP and resistance to poisons" << endl << "How much constitution would you like? (1-25)" << endl;
    	cin >> cCon;
    	if (cCon > 25)
        {   
            cout << "You're trying to set your intelligence too high...which isnt very intelligent! Please choose between 1 and 25." << endl;
            cin >> cCon;
        }  
    	cPoints = cPoints - cCon;
    	cout << endl << "You have " << cPoints << " points left!" << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl << endl;
    	cout << "---------------------------------" << endl << endl;
    
    	cout << "Speed allows your character to land attacks sooner and more often" << endl << "How much speed would you like? (1-25)" << endl;
        cin >> cSpe;
        if (cSpe > 25)
        {   
            cout << "You're trying to set your speed too high. Please choose between 1 and 25." << endl;
            cin >> cSpe;
        }
    	cPoints = cPoints - cSpe;
    	cout << endl << "You have " << cPoints << " points left!" << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    	cout << "---------------------------------" << endl << endl;
    
    	cout << "NinJutsu allows you to learn elite and secret techniques to attack your enemies with" << endl << "How much NinJutsu would you like? (1-25)" << endl;
        cin >> cNin;
        if (cNin > 25)
        {   
            cout << "You're trying to set your NinJutsu too high. Please choose between 1 and 25." << endl;
            cin >> cNin;
        }
    	cPoints = cPoints - cNin;
    	cout << endl << "You have " << cPoints << " points left!" << endl;	
    	cout << "---------------------------------" << endl;
    	cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    	cout << "---------------------------------" << endl << endl;
    
    	if (cPoints > 0)
    	{
    		cout << "You did not spend all of your character points! You may still use " << cPoints << " points." << endl << "Which attribute would you like to add points to?" << endl;
    		cout << "---------------------------------" << endl;
    		cout << "1: Strength" << endl << "2: Intelligence" << endl << "3: Agility" << endl << "4: Constitution" << endl << "5: Speed" << endl << "6: Ninjutsu" << endl << "Please type the number corresponding with the attribute you want to change" << endl;
    		cout << "---------------------------------" << endl;
    		cin >> cLeftOver;
    		
    		if (cLeftOver = 1)
    		{
    			cout << "Strength is the attribute that applies to how much damage your mutant does." << endl << "How much strength would you like? (1-25)" << endl;
    			cin >> cStr;
    			if (cStr > 25)
    			{   
    			cout << "You're trying to set your Strength too high. Please choose between 1 and 25." << endl;
    			cin >> cStr;
    			}
    			cPoints = cPoints - cStr;
    			cout << endl << "You have " << cPoints << " points left!" << endl;	
    			cout << "---------------------------------" << endl;
    			cout << "Strength:     " << cStr << endl << "Intelligence: " << cIntel << endl << "Agility:      " << cAgi << endl << "Constitution: " << cCon << endl << "Speed:        " << cSpe << endl << "NinJutsu:     " << cNin << endl;
    			cout << "---------------------------------" << endl << endl;
    		}
        system ("PAUSE");
    	}

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Looks like you're missing one final } in main.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Work on making your indentation more consistent. It will help finding these types of errors where braces don't match up.
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    31
    yeah, in my program they match up right, when i copied and pasted a lot of it sorta formatted a bit off. So it just looks like i missed a close...hmmm ive been over it a bunch of times and i dont see it.

    I'll look again.

    EDIT: Yep, there it is....thanx for catching that. Im sorry, i should have a been a little more diligent about checking my code.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    I did this too when i was a newbie at C++ programming. What is that? Copying and pasting other people's code! Although it was easy for me, i ended with several lines of code that are difficult to debug.
    Find ways to minimize your basic code, which is inside main(). Only then you'll localise errors and help youself and the others who try to help you!
    I now you said you are new to this, but ignorance is no excuse!! Try to find a C++ book to help you out with the basics, that's what i did!

    That is MY opinion of course.......

  6. #6
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I would also like to add the simple suggestion of getting an automatic indenting app. Many are available for *NIX, should be some freeware things out there for Windows...the thing is if you miss a paren or brace gets unbalanced, this kind of tool seems to help high light those errors easily...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM