I have a program to write and im stuck. It runs but not properly. idk i think my "if" "else" statements are the problem.
here are some sample runs
Enter employee ID ====> 123
Enter payroll status (s/h/c)====> s
Enter monthly salary ====> 5280
Employee ID: 123
Payroll Status: Salaried
Gross Pay: $5280
Enter employee ID ====> 111
Enter payroll status (s/h/c)====> H
Enter number of hours worked this month ====> 80.5
Employee ID: 111
Payroll Status: Hourly
Gross Pay: $1509.38
Enter employee ID ====> 999
Enter payroll status (s/h/c)====> c
Enter total sales for this month ====> 15750.00
Employee ID: 999
Payroll Status: Commissioned
Gross Pay: $1945
for ex. when I enter H for hourly worker it asks for hours worked then it asks me for "total sales this month" and thats supposed to be ask if i enter C for comissioned worker -__-
#include <iostream>
using namespace std;
void getEmployeeData (int*, char*, int*);
float calculateGrossPay(char, 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 (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)
{
cout <<"Enter Employee ID :";
cin >> *id;
cout <<"Enter Payroll Status :";
cin >> *type;
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 (*type == 'C' || *type == 'c');
{
cout <<"Enter total sales for month :";
cin >> *amount;
}
}
float calculateGrossPay(char c, int a)
{
float f;
if (c == 'A' || c == 'a')
f = a + 0;
else if (c == 'H' || c == 'h')
f = 18.75 * a;
else
f = 1000 + a;
return f;
}