Okay, I've tried writing something, but now I have lots and lots of wonderful errors.
global.h
Code:
#include <iostream>
#include <cmath>
#include <vector>
#include <ctime>
using namespace std;
int validateMenuInput(int length);
float getSalary(int hours, float pay);
void addNewEntry(std::vector<database>& employee); //Errors are here
float generateIdNumber();
In here, it says on the line with void addNewEntry() that:
"'database' was not declared in this scope"
"template 1 argument is invalid"
"template 2 argument is invalid"
"ISO C++ forbids declaration of 'employee' with no type"
Looks like it doesn't realize I declare database as a structure later.. How do I make sure the function declaration knows what database is?
main.cpp
Code:
int main()
{
srand((unsigned)time(0));
struct database
{
int idNumber;
int age;
string name;
string title;
int hours;
int wage;
int salary;
};
std::vector<database> employee; //Errors are here
addNewEntry(employee);
cout<<"number: "<<employee[1].number<<"\n";
}
I tried to sort out the errors that'll go away when addNewEntry() works properly.. That left me with some on the line that declares the vector:
"'main()::database' uses local type 'main()::database'"
"trying to instantiate `template<class _Alloc> class std::allocator'"
"template argument 2 is invalid"
"invalid type in declaration before ';' token"
addNewEntry() function:
Code:
void addNewEntry(std::vector<database>& employee)
{
employee.push_back(database());
employee.back().idNumber = generateIdNumber();
cout<<"ID Number: "<<employee.back().idNumber;
cout<<"Enter the employee's name: ";
cin>>employee.back().name;
cout<<"Enter the employee's age: ";
cin>>employee.back().age;
cout<<"Enter the employee's title: ";
cin>>employee.back().title;
cout<<"Enter the employee's wage: ";
cin>>employee.back().wage;
cout<<"Enter the employee's weekly hours: ";
cin>>employee.back().hours;
employee.back().salary = getSalary(employee.back().hours, employee.back().wage);
cout<<"Employee's salary: "<<employee.back().salary;
}
I just included this in case it's important. generateIdNumber() just returns a number between 10001 and 98304, and getSalary() calculates monthly salary with overtime wages for more than 40 hours a week. I doubt they're causing the problem.
Like most errors I'm guessing this is all because of one thing, which I guess is that the program doesn't realize the vector is for database, especially in the declaration for addNewEntry()