C++ End of File error

  • Poly
  • Guru
  • Guru
  • User avatar
  • Posts: 1091
  • Loc: Same place you left me.

Post 3+ Months Ago

Working on an assignment for class, and ran into an error. Not exactly sure what the problem is since all my braces and brackets match up. Anybody able to point out what I'm doing wrong? Error is "Unexpected end-of-file found".

Code: [ Select ]
#include <iostream>
using namespace std;

class ProjectResources
{
    struct project
    {
        char name[15];
        char resourceType[20];
        char skill[15];
        double payRate;
        float hours;
    };

    void main()
    {
        project resources[4] =
        {
            { "Sheila Chu", "Developer", "C++", 38.00, 480},
            { "Steve Dahlman", "Systems Analyst", "SQL", 35.00, 360},
            { "Mike Hammond", "Developer", "C++", 38.00, 480},
            { "Greg McDole", "Developer", "ETL", 36.00, 360},
            { "Heather Tang", "Business Analyst", 32.00, 500}
        };
    
        cout << projectresources[0].name << ", " << projectresources[0].resourceType << ", " << projectresources[0].skill << ", " << projectresources[0].payRate << ", " << projectresources[0].hours << ", " projectresources[0].payrate * projectresources[0].hours << endl;
        cout << projectresources[1].name << ", " << projectresources[1].resourceType << ", " << projectresources[1].skill << ", " << projectresources[1].payRate << ", " << projectresources[1].hours << ", " projectresources[1].payrate * projectresources[1].hours << endl;
        cout << projectresources[2].name << ", " << projectresources[2].resourceType << ", " << projectresources[2].skill << ", " << projectresources[2].payRate << ", " << projectresources[2].hours << ", " projectresources[2].payrate * projectresources[2].hours << endl;
        cout << projectresources[3].name << ", " << projectresources[3].resourceType << ", " << projectresources[3].skill << ", " << projectresources[3].payRate << ", " << projectresources[3].hours << ", " projectresources[3].payrate * projectresources[3].hours << endl;
        cout << projectresources[4].name << ", " << projectresources[4].resourceType << ", " << projectresources[4].skill << ", " << projectresources[4].payRate << ", " << projectresources[4].hours << ", " projectresources[4].payrate * projectresources[4].hours << endl;

        cin.get();

        return;

    }
}
  1. #include <iostream>
  2. using namespace std;
  3. class ProjectResources
  4. {
  5.     struct project
  6.     {
  7.         char name[15];
  8.         char resourceType[20];
  9.         char skill[15];
  10.         double payRate;
  11.         float hours;
  12.     };
  13.     void main()
  14.     {
  15.         project resources[4] =
  16.         {
  17.             { "Sheila Chu", "Developer", "C++", 38.00, 480},
  18.             { "Steve Dahlman", "Systems Analyst", "SQL", 35.00, 360},
  19.             { "Mike Hammond", "Developer", "C++", 38.00, 480},
  20.             { "Greg McDole", "Developer", "ETL", 36.00, 360},
  21.             { "Heather Tang", "Business Analyst", 32.00, 500}
  22.         };
  23.     
  24.         cout << projectresources[0].name << ", " << projectresources[0].resourceType << ", " << projectresources[0].skill << ", " << projectresources[0].payRate << ", " << projectresources[0].hours << ", " projectresources[0].payrate * projectresources[0].hours << endl;
  25.         cout << projectresources[1].name << ", " << projectresources[1].resourceType << ", " << projectresources[1].skill << ", " << projectresources[1].payRate << ", " << projectresources[1].hours << ", " projectresources[1].payrate * projectresources[1].hours << endl;
  26.         cout << projectresources[2].name << ", " << projectresources[2].resourceType << ", " << projectresources[2].skill << ", " << projectresources[2].payRate << ", " << projectresources[2].hours << ", " projectresources[2].payrate * projectresources[2].hours << endl;
  27.         cout << projectresources[3].name << ", " << projectresources[3].resourceType << ", " << projectresources[3].skill << ", " << projectresources[3].payRate << ", " << projectresources[3].hours << ", " projectresources[3].payrate * projectresources[3].hours << endl;
  28.         cout << projectresources[4].name << ", " << projectresources[4].resourceType << ", " << projectresources[4].skill << ", " << projectresources[4].payRate << ", " << projectresources[4].hours << ", " projectresources[4].payrate * projectresources[4].hours << endl;
  29.         cin.get();
  30.         return;
  31.     }
  32. }


Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

You need a semicolon (;) after your closing brace for the class declaration. Add a newline as well since many compilers will complain about that.

Also, you shouldn't be inlining main(), but I'll leave that to your instructor ;)
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Other possible errors:

Code: [ Select ]
cout << projectresources[0].name...........


Are you sure you do not mean:

Code: [ Select ]
cout << resources[0].name...... etc


Since resources[] are holding the structures values (projectresources is the class name). Also you are defining a array with 4 values:

Code: [ Select ]
project resources[4]


This will give you a array looking like this:
resources[0]
resources[1]
resources[2]
resources[3]

Not an array of 5 witch you probably think it would when you try to pass this array 5 values:

Code: [ Select ]
project resources[4] =
    {
      { "Sheila Chu", "Developer", "C++", 38.00, 480},
      { "Steve Dahlman", "Systems Analyst", "SQL", 35.00, 360},
      { "Mike Hammond", "Developer", "C++", 38.00, 480},
      { "Greg McDole", "Developer", "ETL", 36.00, 360},
      { "Heather Tang", "Business Analyst", 32.00, 500}
    };
  1. project resources[4] =
  2.     {
  3.       { "Sheila Chu", "Developer", "C++", 38.00, 480},
  4.       { "Steve Dahlman", "Systems Analyst", "SQL", 35.00, 360},
  5.       { "Mike Hammond", "Developer", "C++", 38.00, 480},
  6.       { "Greg McDole", "Developer", "ETL", 36.00, 360},
  7.       { "Heather Tang", "Business Analyst", 32.00, 500}
  8.     };


This may compile but can course problematic behavior.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 139 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.