Link to home
Start Free TrialLog in
Avatar of bnblazer
bnblazer

asked on

newbie with compiler/syntax errors

Please be gentle.  I am new to C++ and trying to get an understanding  of it by working through some tutorials.  The one I am working on now has to do with "structs."  Essentially, I need to build a struct that will take some employee data and then enter it into an array.  I think
I have the basic concept down, but I am getting some compiler errors that I have never seen before, and am having a hard time figuring them out.  I am sure that it just some stupid typos, but I have been looking at this too long and think that I can not see them.  You help in
figuring this out is sincerely appreciated.

My cin statements are getting the error: "Expecting primary expression before '.'"

My array (at the end of the for) is getting the same error except is says "...before ']'"

Here is a code snippet:

#include <iostream>
using namespace std;

int main (int argc, char * const argv[]) {
      
      int i;
      int numEmp;
      
      struct employee {
            int id;
            char name[20];
            float rate;
            float hours;
      };
      
      employee record[numEmp];
      
      cout << "\n**************************************************" << endl;
      cout << "********** EMPLOYEE DATA RECORD PROGRAM **********" << endl;
      cout << "**************************************************" << endl;
      cout << "This program will take employee records one at a time." << endl;
      cout << "You will be prompted for the number of employees you want to enter" << endl;
      cout << "You will then enter ID#, Name, Rate, and Hours for each employee" << endl;
      cout << "When you are done, a chart will print to show you all data entered." << endl << endl;
      

      cout << "Please enter the number of employees you want to enter: ";
      cin >> numEmp;
            
      for (i=0; i < numEmp; i++)
      {
            cout << "Employee Number: ";
            cin >> employee.id;
            cout << "Employee Last Name: ";
            cin >> employee.name;
            cout << "Employee Rate: ";
            cin >> employee.rate;
            cout << "Employee Hours: ";
            cin << employee.hours;
            record[employee];
            }
}

Again, thank you for your help.  I have pegged my frustration meter, and am feeling a bit embarrassed that I cant figure this one out myself.
ASKER CERTIFIED SOLUTION
Avatar of brettmjohnson
brettmjohnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your array allocation is also wrong.  You can create a static array if you know the number of elements at compile time:

employee record[100];

However, if you don't know the size in advance, you will have to dynamically allocate the array after you do know the size:

cout << "Please enter the number of employees you want to enter: ";
cin >> numEmp;

employee * record = new employee[numEmp];



         
Avatar of bnblazer
bnblazer

ASKER

Thank you for your help.  I had to change one thing from what you wrote, but you got me on the right path.

cin >> record[i].id;

Thank you again,
Brian