Help - Inputing data from file to Arrays

write a c++ program that read from a datafile 10 records. The records consist of:

Employee Name (array of 10)
Employee Wages (array of 10)
Employee Hours Worked (array of 10)
(The data should be read in from the main function)

Once data is read into the array should be passed to a function where you are to calculate and print each employee regular pay and bonus pay.



so far i have this but have no idea how to accomplish the goal.
So far i am getting this error..

main.cpp: In function 'int main()':
main.cpp:42:30: error: size of array 'name' has non-integral type 'std::string [10] {aka std::basic_string [10]}'
string name[Employee_Name];

------------------------------------------------------------------------

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include "header.h"

using namespace std;

//create object
ifstream datafile;

//function prototype
void payroll(string, double, double);

//Global bonus constant
const float bonus = .05;

int main()
{
//need to read in data from file somewhere in the main
//this is a call to head function from header.h file.
head();

//open file. text.txt has info for 10 employees like so..."Joe 10 40"..etc
datafile.open("name.txt");


//arrays
string Employee_Name[10];
double Employee_Wage[10];
double Employee_Hours_Worked[10];

string name[Employee_Name];
double wage[Employee_Wage],
double hours[Employee_Hours_Worked];




// once its read in, now i need to pass it to the function that calulates and print
while (!datafile.eof())
{

datafile >> name[Employee_Name] >> wage[Employee_Wage] >> hours[Employee_Hours_Worked];
payroll(name[Employee_Name], wage[Employee_Wage], hours[Employee_Hours_Worked]);
cout << "Thats all folks!"

}
datafile.close();
return 0;
}


void payroll(string Pname, double Pwage, double Phours)
{
double subtotal, total;
subtotal = Phours*Pwage;
total = subtotal + (subtotal*bonus);
cout << setw(10) << "Name" << setw(10) << "Wage" << setw(10) << "Hours" << setw(10) << "RegPay" << setw(10) << "Bonus Pay" << endl;
cout << setw(10) << Pname << setw(10) << Pwage << setw(10) << Phours << setw(10) << subtotal << setw(10) << total << endl;
}
string name[Employee_Name];
You can't declare the size of an array with just another array. You need to use a constant number for the array size.

string Employee_Name[10];
This is correct.
Topic archived. No new replies allowed.