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.
LVL 1
bnblazerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brettmjohnsonCommented:
The compiler tells you which line the error occurs on.  The actual problem is likely on that line (or the ones immediately preceding it).

In your case, employee is an array.  You need to reference a specific array element.

cin >> employee[i].id;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brettmjohnsonCommented:
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];



         
0
bnblazerAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.