Well I’m making an program about payrolls and I’m stuck. In the program, after the user has entered the number of employees, I have to make an loop, allowing the user to enter information for each of the employees. Then the data entered is to be stored in my employees array, which I made. Ive attempted my problem with the while(numberOfEmployees < MAXSIZE) part of my program. Is that right?
This is what I have now:
#include <iostream>
using namespace std;
const int MAXSIZE = 20;
struct EmployeeT
{
char name[MAXSIZE];
char title;
double gross;
double tax;
double net;
};
EmployeeT employees[MAXSIZE];
int main()
{
cout << "How many Employees? ";
int numberOfEmployees;
cin >> numberOfEmployees;
while(numberOfEmployees > MAXSIZE)
{
cout << "Error: Maximum number of employees is 20\n";
cout << "How many Employees? ";
cin >> numberOfEmployees;
}
int name;
int title;
double gross;
double tax;
double net;
for (int count=0; count<numberOfEmployees; count++)
{
cout << "Name: \n";
cin >> employees[ count ].name;
cout << "Title: \n";
cin >> employees[ count ].title;
cout << "Gross: \n";
cin >> employees[ count ].gross;
cout << "Tax: \n";
cin >> employees[ count ].tax;
cout << "Net: ";
cin >> employees[ count ].net;
}
}
I just updated it to this. My last question is how do I get the second loop to keep working as many times as the user wants. For as many employees the user types in?
Several problems:
1- Place a i++ somewhere inside the while loop
(Why not use a for loop?)
2- name and title should probably be a string:
3- the while condition should be:
(Edit: I see you just corrected that one)
Edit: I just noticed you always write to the same variables. Write to employees[i].name etc. instead.
Does that solve your problem?