B
bnblazer
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.
Brian
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.
Brian