954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getting strange values in display???

Hello,
I am getting strange values in my display for the salary, hourly or commission.
I do have to use arrays and wondering if there is a simple fix. Maybe I need a pointer to the array? If anyone has a suggestion, please let me know.
Thank you.

#include
#include
using namespace std;
#include
int getEmployeeData (string[], char[], const int, double[]);
void displayEmployeeInfo (string[], char[], int, double[], double[]);
bool isValidStatus(char);
bool tryAgain();
bool isValidID (string);
float calculateGrossPay(char[], double[], int, double[]);

int main()
{
const int numEmp = 4;
string ID[numEmp];
double Money[numEmp];
double totalPayroll[numEmp];
char pyrllSt[numEmp];
double grossPay[numEmp];
getEmployeeData(ID, pyrllSt, numEmp, Money);
displayEmployeeInfo(ID, pyrllSt, numEmp, grossPay, totalPayroll);

return 0;
}


int getEmployeeData (string ID[], char pyrllSt[], const int numEmp, double Money[])
{
for (int index = 0; index < numEmp; index++)
{
do
{
cout << "Enter employee ID:" << index +1 << endl;
cin >> ID[index];
} while(!isValidID(ID[index]));
do
{
cout << "Enter payroll status:" << endl;
cin >> pyrllSt[index];
}while (!isValidStatus(pyrllSt[index]));

if (pyrllSt[index] == 's' || pyrllSt[index] == 'S')
{
cout << "Enter the monthly salary:" << endl;
}

else if (pyrllSt[index] == 'h' || pyrllSt[index] == 'H')
{
cout << "Enter the number of hours worked this month:" << endl;
}

else if (pyrllSt[index] == 'c' || pyrllSt[index] == 'C')
{
cout << "Enter total sales for this month: " << endl;
}
cin >> Money[index];
}
return Money[index];
}
bool isValidStatus(char pyrllSt)
{
if (pyrllSt == 's' || pyrllSt == 'S' || pyrllSt == 'h' || pyrllSt == 'H' || pyrllSt == 'c' || pyrllSt == 'C')
{
return true;
}
else
{
tryAgain();
cout << "Re-enter 's' or 'S' for salaried, 'h' or 'H' for hourly," << endl;
cout << "'c' or 'C' for commissioned." << endl;
return false;
}
}

bool tryAgain()
{
char quit;

cout << "Do you want to try again or quit?" << endl;
cout << "Type Q or q to quit, any other key to continue: " << endl;
cin.get(quit);

if (quit != '\n')
{
cin.ignore();
}

cin.get(quit);

if (quit == 'q' || quit == 'Q')
{
return false;
}

else
{
return true;
}
}


void displayEmployeeInfo (string ID[], char pyrllSt[], const int numEmp, double grossPay[], double totalPayroll[])
{
for (int index = 0; index < numEmp; index++)
{
cout << ID[index] << endl;
cout << pyrllSt[index] << endl;
cout << grossPay[index] << endl;
}
cout << totalPayroll[index];
}

bool isValidID(string ID)
{
for (int index = 0; index < ID.length(); index++)
{
if(ID[0] < 48 || ID[0] > 57)
{
cout << "*** INVALID PAYROLL ID ***" << endl;
return false;
}
}
if(ID.length() != 3)
{
cout << "*** INVALID PAYROLL ID ***" << endl;
return false;
}
else
{
return true;
}
}

float calculateGrossPay (char pyrllSt[], double grossPay[] , const int numEmp, double Money[])
{
for (int index = 0; index < numEmp; index++)
{
if (pyrllSt[index] == 's' || pyrllSt[index] == 'S')
{
grossPay[index] = Money[index];
}
if (pyrllSt[index] == 'h' || pyrllSt[index] == 'H')
{
grossPay[index] = Money[index] * 18.75;
}
if (pyrllSt[index] == 'c' || pyrllSt[index] == 'C')
{
grossPay[index] = (Money[index] * 0.06) + 1000.00;
}
}
return grossPay[index];
}

hill0ster
Newbie Poster
18 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

Strange values typically mean that you've forgotten to initialize a variable. This is the bug you should be searching for using print statements and a debugger if you have one.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

One big hint: in your main() you don't call calculateGrossPay() anywhere.

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You