so we are starting arrays and our task is to go back to our assignment 2 (functions) and he wants us to run the program using arrays.
im pretty stuck and have no clue what to do.
heres how assignment (functions)2 looks
#include <iostream>
using namespace std;
void getEmployeeData (int*, char*, int*);
float calculateGrossPay(char, int);
bool isValidStatus(char);
//bool getEmployeeData(int);
int main()
{
int pId;
char pType;
int pAmount;
getEmployeeData (&pId, &pType, &pAmount);
float cost = calculateGrossPay(pType, pAmount);
if (pType == 'S' || pType == 's')
{
cout <<"Employee ID: " << pId << endl;
cout <<"Payroll Status: " << pType <<"alaried" << endl;
cout << "Gross Pay: " << '$' << cost << endl;
}
else if (pType == 'H' || pType == 'h')
{
cout <<"Employee ID: " << pId << endl;
cout <<"Payroll Status: " << pType <<"ourly" << endl;
cout << "Gross Pay: " << '$' << cost << endl;
}
else if (pType == 'C' || pType == 'c')
{
cout <<"Employee ID: " << pId << endl;
cout <<"Payroll Status: " << pType <<"omissioned" << endl;
cout << "Gross Pay:$ " << '$' << cost << endl;
}
system("pause");
return 0;
}
void getEmployeeData (int* id, char* type, int* amount)
{
bool result;
do {
cout <<"Enter Employee ID :";
cin >> *id;
} while (*id <= 0);
do {
cout <<"Enter Payroll Status :";
cin >> *type;
result = isValidStatus(*type);
} while (result == false);
if (*type == 'S' || *type == 's')
{
cout <<"Enter monthly salary :";
cin >> *amount;
}
else if (*type == 'H' || *type == 'h')
{
cout <<"Enter number of hours worked this month :";
cin >> *amount;
}
else if(*type == 'C' || *type == 'c')
{
cout <<"Enter total sales for month :";
cin >> *amount;
}
}
float calculateGrossPay(char c, int s)
{
float f;
if (c == 'S' || c == 's')
f = s + 0;
else if (c == 'H' || c == 'h')
f = 18.75 * s;
else
f = 1000 + s ;
return f;
}
bool isValidStatus(char c)
{
if (c == 'S' || c == 's' || c == 'H' || c == 'h' || c == 'C' || c == 'c')
return true;
else
{
cout <<"Re-enter: 's' or 'S' for salaried, 'h' or 'H' for hourly,'c' or 'C' for commissioned :";
return false;
}
}
our new assignment is run this program with arrays.
this is a sample run of how it should look like
Enter employee ID ====> 123
Enter payroll status (s/h/c)====> s
Enter monthly salary ====> 5280
Enter employee ID ====> 111
Enter payroll status (s/h/c)====> H
Enter number of hours worked this month ====> 80.5
Enter employee ID ====> 999
Enter payroll status (s/h/c)====> c
Enter total sales for this month ====> 15750.00
Enter employee ID ====> -1
Employee ID Payroll Status Gross Pay
123 Salaried $5280.00
111 Hourly $1509.38
999 Commissioned $1945.00
this is what i got so far
#include <iostream>
using namespace std;
void getEmployeeData(int [ ], int);
void displayEmployeeInfo (int [ ], int);
int main()
{
int stoodunce[4];
getEmployeeData(stoodunce, 4);
displayEmployeeInfo(stoodunce, 4);
cout << endl;
system("pause");
return 0;
}
void getEmployeeData(int id[ ], int size)
{
for (int x = 0; x < size; x++)
{
cout << "Enter Employee ID : ";
cin >> id[x];
}
}
void displayEmployeeInfo (int val[ ], int size)
{
for (int x = 0; x < size; x++)
cout << "Employee ID:" <<
val[x] << endl;
}
the next thing to do is payroll status thats the part im stuck on.
btw some hints
getEmployeeData - This function is called once from main and stores in the first three arrays the values inputted by the user for the employee ID, payroll status and either the input salary, hours worked, or monthly sales (as determined by the payroll status). This function ends when the user has inputted data for 4 employees or inputs a negative employee ID to stop input, whichever comes first. It returns to main the number of employees (up to 4 but could be less) that were stored in the arrays
The first array will hold the employee 3 digit ID. You can assume that the user entered a valid whole number. However, you cannot assume a 3 digit number will be entered. You must check to make sure that the user did not enter more or less digits than 3. (You don't need to check for a negative number since that ends input, as explained with getEmployeeData)
The second array will store the payroll status.
The third array will store either the input salary, hours worked, or monthly sales (as determined by the payroll status). Again there is no error-checking; you may assume the user enters valid values.
The fourth array will store the calculated gross pay.
idk if im doing it right or not, please help me.