can anyone tell me why my output gives me - numbers?

#include <iostream> 
#include<iomanip>
using namespace std; 
void getEmployeeData(int [ ], char [ ], int [ ], int);
void displayEmployeeInfo (int [ ], char [ ], float [ ], int);
float calculateGrossPay (char [ ], int [ ], float [ ],int);
bool isValidStatus(char);
//bool isValidID(int);


int main() 
{ 
int stoodunce[4]; //ep id
char stoodunce1[4];//payroll status
int stoodunce2[4];//input if its s/h/c
float stoodunce3[4];//calculates grosspay



getEmployeeData(stoodunce, stoodunce1 , stoodunce2,  4);
calculateGrossPay(stoodunce1, stoodunce2, stoodunce3, 4);
displayEmployeeInfo(stoodunce, stoodunce1, stoodunce3, 4);

system("pause");
return 0; 
} 

void getEmployeeData(int id[ ], char ps[ ],int input[ ], int size)

{
bool result;
//bool result2;

for (int x = 0; x < size; x++)
{
//do {
cout << "Enter Employee ID : ";
cin >> id[x];
//result2 = isValidID(id[x]);
//} while (result2 == false);
do {
cout <<"Enter Payroll Status (s/h/c):";
cin >> ps[x];
result = isValidStatus(ps[x]);  
} while (result == false);
if (ps[x] == 'S' || ps[x] == 's')
{
	cout <<"Enter Monthly Salary :";
	cin >> input[x];
}
else if (ps[x] == 'H' || ps[x] == 'h')
{
	cout <<"Enter total hours worked this month :";
	cin >> input[x];

}
else if (ps[x] == 'C' || ps[x] == 'c')
{
	cout <<"Enter total sales this month :";
	cin >> input[x];
}
}

}

float calculateGrossPay ( char ps [ ], int input [ ], float [ ], int size)
{
float amount;

for (int x = 0; x < size; x++)
{
if (ps[x] == 'S' || ps[x] == 's')
	{
		 amount = input[x] + 0;
	}

else if (ps[x]== 'H' || ps[x] == 'h')
	{
		amount = input[x] * 18.75;
	}

else
	{
		amount = input[x] + 1000;
	}

}
return amount;
}

bool isValidStatus(char ps)
{


	if (ps == 'S' || ps == 's' || ps == 'H' || ps == 'h' || ps == 'C' || ps == 'c')
		return true;
	else 
	{
		cout <<"Re-enter: 's' or 'S' for salaried, 'h' or 'H' for hourly,'c' or 'C' for commissioned :";
		return false;
	}
}

//bool isValidID(int id)
//{
	//if (id <= 2 || id >= 4)
	//{
		//cout << " Re-enter a 3 digit number:" << endl;
		//return false;
	//}
	//else 
	
		
		//return true;
	
//}


void displayEmployeeInfo (int val[ ],char val1[ ], float val2 [ ], int size)
{
for (int x = 0; x < size; x++)
cout << "Employee ID:" << val[x] << " " << "Payroll Status" << " " << val1[x] << " " <<"GrossPay" << " " << val2[x] << endl;
}

thanks.

I believe that this may be related to your problem..

You are passing in objects to your functions 'by value' which necessitates the need to save a return value from your functions.

//you create this stuff
int stoodunce[4]; 
char stoodunce1[4];
cfloat stoodunce3[4];

//and pass it into these functions 'by value' hence, cannot affect them in memory..  you'd have to save a return value from the functions
getEmployeeData(stoodunce, stoodunce1 , stoodunce2, 4);
calculateGrossPay(stoodunce1, stoodunce2, stoodunce3, 4);
displayEmployeeInfo(stoodunce, stoodunce1, stoodunce3, 4);

The current sheme you are trying to use (which I like because it is more efficient than passing stuff around by value) is to have your functions to affect variables in memory; thus eliminating the need to save function return values.

So, to turn your code into an efficient 'pass by reference' program, be sure to prototype your functions to accept memory addresses rather than having to make copies of its arguments. Luckily, the answer is very simple:

//Function Prototypes
void getEmployeeData(int*&, char*&, int*&, int*&);
void displayEmployeeInfo (int*&, char*&, float*&, int*&);
float calculateGrossPay (char*&, int*&, float*&, int*&);

To pass variables into your functions by reference (using the & 'address' operator) you give them the ability to directly affect the variables in memory.

Suggestion:

I see that you are down with commenting out pieces of code, which is a very usefull tool. To make life simplier, you can place a /* at line #103 and a */ at line #107 and comment out several lines of code at once without having to // comment out every line.

Edited 7 Years Ago by Clinton Portis: n/a

didnt seem to work, and i have to use the array method which means i gotta used "[ ]" i think... example
void getEmployeeData(int [ ], char [ ], int [ ], int);

Passing an array e.g., func(type a[]) is equivalent to passing func(type * a) anyway, so you already had the pointers working for you. I'm taking a look into whether you may have swapped one of your arrays.

EDIT: Found it, this is within your definition: float calculateGrossPay ( char ps [ ], int input [ ], [b]float [ ] [/b], int size) so in the end you were getting whatever garbage was in stoodence3 upon declaration.

Edited 7 Years Ago by jonsca: n/a

I'll put down my crack pipe now and state the arrays can only be passed by reference.. what was I thinking...

Edited 7 Years Ago by Clinton Portis: n/a

Passing an array e.g., func(type a[]) is equivalent to passing func(type * a) anyway, so you already had the pointers working for you. I'm taking a look into whether you may have swapped one of your arrays.

EDIT: Found it, this is within your definition: float calculateGrossPay ( char ps [ ], int input [ ], [b]float [ ] [/b], int size) so in the end you were getting whatever garbage was in stoodence3 upon declaration.

wait what? sorry im have a little trouble understanding what your saying

Look closely.. something isn't right here.

//line #66, parameter list
float calculateGrossPay ( char ps [ ], int input [ ], [B]float [ ][/B] , int size)

Edited 7 Years Ago by Clinton Portis: n/a

No, cause then your program breaks, completely. You need to pass in an array to accept the "amount" in that slot (your function doesn't even assign your amounts to an array like it should), as that array is passed into your output function. For what ever reason it compiled that way but it almost shouldn't have.

In other words, stick a name on that float [] and use it in your function.

Edited 7 Years Ago by jonsca: n/a

oh ok ill try to see what i can do even though im kind of lost grr

How come you named the other parameters of the function? So you can use them in the function body (among other things).

This article has been dead for over six months. Start a new discussion instead.