Values not being displayed in function

arrays only visable in main and admin_Options

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1088 Views - Last Post: 05 December 2007 - 05:07 PM Rate Topic: -----

#1 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Values not being displayed in function

Post icon  Posted 04 December 2007 - 11:28 AM

I've been working on this semester project for over two weeks, everyone on here has been very helpful. I've tested it out and it reports no errors. But however, i can not seem to get the values stored in the arrays when calling the separate functions. I tested to see if they were being stored in main after being entered in admin_Options and they show up if I add the code, but when I attempt to pass the arrays to the other functions, I either get garbage or nothing on my screen.

Can someone please overlook this... I've checked my code and can't seem to find where the problem is coming from, but maybe a second pair of eyes can help me find it quicker.

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query 
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char [], double [], char [], int);
void empByDept(char, char [], char [], int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char [], double [], char [], int);

int admin_Options(char empNames[], double salaries[], char depts[], int count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	 
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	 
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
		
	 do {		
		   if((addRecord == 1) && (count <25)){
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (YES or NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
		   }//end if
		   
		   else if(addRecord = 2){ 
				break;
		   }//end else
		   if (count <25){
		   cout << "Max number of records is 25!\n";
		   system("pause");
		   break;
		   }//end if
		   
		   else
		   break;					   
	 }while (count <25);//end do
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice = ' ';
	  char empNames[25] = {' '};
	  double salaries[25] = {0.0};
	  char depts[25] = {' '};
	  int i = 0;
	  int count;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query, from the following list:\n";
				for (i=0; i<count; i+=1)
				{
				cout << depts[i];
				}
			cout << endl;
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3); 
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char empNames[], double salaries[], char depts[], int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "List of all employees:\n";
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char empNames[], char depts[], int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (depts[i] = deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{  
	   double lowest = 0.00;
	   if (salaries[i] > lowest) lowest = salaries[i];
	   return lowest;
	}//end else
}//end calcLowSal function



Is This A Good Question/Topic? 0
  • +

Replies To: Values not being displayed in function

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4299
  • View blog
  • Posts: 12,060
  • Joined: 18-April 07

Re: Values not being displayed in function

Posted 04 December 2007 - 12:38 PM

Lots and lots of things going wrong here. Hopefully I can give you a good start on understanding what is going on here. First I am going to assume you are not coding this in a compiler like VC++ because upon running this I kept getting errors referring to your count variable not being initialized before being used. So just for completeness sake, make sure you set your int count = 0;.

So to test your theory about passing arrays, I decided to take the least complex of your functions and used number 4, calculating the lowest salary. Upon looking at the function I noticed it was going to give you bad results just because you were comparing each salary to the lowest and taking the "highest" salary. Remember, to find the lowest it has to be lower than the previous lowest value. So I recoded your lowest salary function to look like this...

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) { 
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function



As you can see, I immediately test the count value before continuing. If it is less than one, no use going into our loop. I then make sure to return a value of 0.0 if that is the case (make sure all paths of execution result in a return of a result).

I then take the first salary of the salaries array and go into a loop starting from the next salary on comparing it to see if it is LOWER than the previous value. If it is, then I set the lowest to that salary value. At the end, lowest has the lowest value from the salary array.

Ok, with that out of the way, I wanted to see if your salaries array was being passed correctly. Guess what, it is. You salaries array wasn't the problem here. It was your count variable! You added to count in admin_options when you were adding employees, but you forgot one subtle thing... because you have created count in main, you should have passed count by reference so that every time you incremented count in admin_options, it would be reflected back in main. You were adding to a COPY of count in admin_options. So after the function was done, main's version of count was still 0. Then guess what? You passed on count = 0 to your salaries function and your function was screwing up.

So how do we fix this? Simple, your count parameter to admin_options needed an ampersand sign.

int admin_Options(char empNames[], double salaries[], char depts[], int &count)//options for adding or modifying current employees
{  
	 ....
}



Notice how count has an ampersand in front of the name. This tells the function not to make a copy of count, but use the address of the previous count defined back in main. So when we increment it, we are incrementing the count back in main.

Make sure this change is also reflected in the declaration of the function....

// Declaration for admin_Options
int admin_Options(char [], double [], char [], int &);



Another thing is how you setup your employee names and departments. You created arrays of chars, not an array of character strings. So when you type in the last name of "Doe" it would only take the "D" and throw away the rest.

You need to setup your array of names like so...

// Create a pointer array of 25 character string pointers
char **empNames = new char*[25];

// Set each array pointer to point to a new character string of length 25.
for (int i = 0; i < 25; i++) {
	 empNames[i] = new char[25];
}



So what does this mean for your function signatures and declarations? For empName instead of empName[] you will need to have char **empName. Make your declarations match.

Once you do that, you will start seeing your names come out correctly. Btw... after all these fixes mentioned, it looks like it will also fix your listing of employees and some of the other functions are coming online as well. So make the changes and fully test everything. Then you will be ready to continue debugging the rest (like checking empByDept... you use a single = instead of == when checking deptChoice).

The fully modified code is below...


/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char [], int);
void empByDept(char, char **, char [], int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char [], int &);

int admin_Options(char **empNames, double salaries[], char depts[], int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	//system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
		
	 do {		
		   if((addRecord == 1) && (count <25)){
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (YES or NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
		   }//end if
		  
		   else if(addRecord = 2){
				break;
		   }//end else
		   if (count <25){
		   cout << "Max number of records is 25!\n";
		   system("pause");
		   break;
		   }//end if
		  
		   else
		   break;					  
	 }while (count <25);//end do
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice = ' ';
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char depts[25] = {' '};
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query, from the following list:\n";
				for (i=0; i<count; i+=1)
				{
				cout << depts[i];
				}
			cout << endl;
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char depts[], int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "List of all employees:\n";
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char depts[], int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (depts[i] == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) { 
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function



Keep in mind that there is more work to do on this, but this should get you printing output in the correct format and such. Keep up the good work!

"At DIC we be code correcting, employee adding code ninjas!" :snap:
Was This Post Helpful? 0
  • +
  • -

#3 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 12:53 PM

Thanks alot for you help Marty. I'm eager to learn, but as I said... sometimes you need a second pair of trained eyes to spot the errors.

If there's anyway I can help you out on here, up your rep(don't know how), or paypal you a few $$ for helping me out, let me know.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4299
  • View blog
  • Posts: 12,060
  • Joined: 18-April 07

Re: Values not being displayed in function

Posted 04 December 2007 - 01:13 PM

We are volunteer and always willing to help. All we ever ask for is that you tell a few programmer friends about the site and a link to us on any site you may have. That way we can continue helping more and more people and share the knowledge!

Thanks again for helping us out. :)
Was This Post Helpful? 0
  • +
  • -

#5 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 07:54 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?


/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (deptChoice == **depts)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{ 
  double total_Sal = 0.00;
  double avg_Sal = 0.00;
  
  if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
	}//end if
	else
	{
	for (int i=0; i<count; i+=1)
	total_Sal = total_Sal + salaries[i];
	}//end else
	avg_Sal = total_Sal/count;
	return avg_Sal;
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=0; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function



This post has been edited by djkaotix: 04 December 2007 - 07:56 PM

Was This Post Helpful? 0
  • +
  • -

#6 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 08:37 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#7 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 09:01 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#8 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 09:22 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#9 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 11:17 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#10 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 11:30 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#11 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 04 December 2007 - 11:50 PM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#12 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4299
  • View blog
  • Posts: 12,060
  • Joined: 18-April 07

Re: Values not being displayed in function

Posted 04 December 2007 - 11:54 PM

You might want to recode that function to loop through the array and compare it to deptChoice. Remember it is an array, so you are going to need subscripts on depts. To compare it against deptChoice, you are going to have to make deptChoice more than just a char, it needs to be a char string. You compare the two using strcmp().

So you need to accomplish the following tasks...

1) Make deptChoice a character string.
2) Change the signature of empByDept to accept a character string (make sure the declaration matches.
3) Change **depts to use a subscript
4) Lastly, compare depts and deptChoice using strcmp().

Once you make these changes, you will be up and running.

Enjoy! :)
Was This Post Helpful? 0
  • +
  • -

#13 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 05 December 2007 - 06:27 AM

Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function



Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function



Thanks again to Marty for your help. I figured out the problem with entering in the names, now it's working almost flawless, except for the display empByDept. I can seem to parse those records correctly from the array.

Not only that, but only the first character is read. Why's it doing that?

/*
  Name: Employee Records (list emps/lists emps by dept/calc avg/calc lowest)
		[supports up to 25 users]
  Author: Gus Diaz
  Description: This program is designed to store employee records, including salary and dept information.
			   The user interface allows you to query by dept, salary status, or list all employees.			  
			  
  Input: admin_Choice, empNames[], salaries[], depts[], addRecord, searchFor, choice, deptChoice
  Processing: function empList -- lists all employee's
			  function empByDept -- displays employee's from a dept query
			  function calcAvgSal -- calculates the avg. employee salary
			  function calcLowSal -- calculates the lowest salary
			  function admin_Options -- user menu to add and modify employee's
  Output: list of all employees,
		  list of employees from a specific dept,
		  display of avg salary,
		  display of lowest salary.
*/

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>

using namespace std;

//function prototype
void empList(char **, double [], char **, int);
void empByDept(char, char **, char **, int);
double calcAvgSal(double [], int);
double calcLowSal(double [], int);
int admin_Options(char **, double [], char **, int &);

int admin_Options(char **empNames, double salaries[], char **depts, int &count)//options for adding or modifying current employees
{	
	int admin_Choice = 0;
	int addRecord;
	char searchFor = ' ';
	int i = 0;  
	
	do
	{
	system ("cls");	
	//set num to maximum number of elements in array
	int num = 25;
	
	//display admin menu
	cout << "Administrative Options\n";
	cout << endl;
	cout << "1. Add new employee record\n\n";
	cout << "0. Return to previous menu\n";
	cout <<endl;
	cout << "Choice:";
	cin >> admin_Choice;
		
	switch (admin_Choice){
	 case 1: //enter in new emp. data
	
	 //check to see if array is full
	 if (count >=25){
	 cout << "Max number of records is 25!\n";
	 system("pause");
	 break;
	 }//end if
	
	 else
	 {
	 cout << endl;
	 cout << "Please enter employee's last name: ";
	 cin >> empNames[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's salary: ";
	 cin >> salaries[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 cout << "Please enter employee's department: ";
	 cin >> depts[i];
	 cin.ignore(100,'\n');
	 cout << endl;
	 count = count + 1;
	 cout << "Would you like to add another record? (1-YES or 2-NO)\n";
	 cin >> addRecord;
	 
	 do{
		   i+=1;
		   cout << endl;
		   cout << "Please enter employee's last name: ";
		   cin >> empNames[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   cout << "Please enter employee's salary: ";
		   cin >> salaries[i];
		   cout << endl;
		   cout << "Please enter employee's department: ";
		   cin >> depts[i];
		   cin.ignore(100,'\n');
		   cout << endl;
		   count = count + 1;
		   cout << "Would you like to add another record? (1-YES or 2-NO)\n";
		   cin >> addRecord;
		   cin.ignore(100,'\n');
		   addRecord = toupper(addRecord);
							   
		  if (count >=25) {
			 cout << "Max number of records is 25!\n";
			 system("pause");
			 break;
			 }
	 }while (addRecord !=2);//end do while
		
	 case 0: //return to previous menu
	 break;
			  
	 default:
	 cout << endl;
	 cout << "Your input was invalid & could not be processed.\n";  
	 }//end of switch
	 }
}while (admin_Choice !=0);//end of do while
return empNames[i], salaries[i], depts[i], count;
}//end admin_Options function


int main()
{
	  //declare constants and variables
	  int choice = 0;
	  char deptChoice;
	  char **empNames = new char*[25];

	  for (int i = 0; i < 25; i++) {
		  empNames[i] = new char[25];
	  }
	  double salaries[25] = {0.0};
	  char **depts = new char*[25];
	  
	  for (int i = 0; i < 25; i++) {
		  depts[i] = new char[25];
	  }
	  int i = 0;
	  int count = 0;//employee counter
	  
	  do{
	  //display menu
	  system ("cls");
	  cout << "Welcome to _______ \n";
	  cout << "Please chose from the following menu options:\n\n";
	  cout << "1. List all employees with their data (name, department, salary)\n";
	  cout << "2. Find all employees in a certain department.\n";
	  cout << "3. Calculate the average salary for all employees.\n";
	  cout << "4. Calculate the lowest salary.\n\n";
	  cout << "9. Administrative options. (Add Employee(s))\n";
	  cout << "0. Exit\n\n";
	  cout << "Choice:";
	  cin >> choice;
	  
	  switch (choice){
	   case 1: //lists all employees along with their data
			cout << "List of all employees:\n";
			empList(empNames, salaries, depts, count);
			system ("pause");
			break;
	   case 2: //list employees for specific dept.
			if (count < 1)
			{
				 cout << "No Records to display. Try entering employee data first!\n";
				 system ("pause");
				 break;
			}//end if
			else
			{
				cout << "Please type the name of the department you wish to query,\nfrom the following list:\n";
				for (int i=0; i<count; i+=1)
				{
				cout << depts[i] << endl;
				}
			cout << endl;
			cout << "Choice:";
			cin >> deptChoice;
			cin.ignore(100,'\n');
			//displays all employees from user selected dept.
			cout << "List of all employees from " << deptChoice << ":\n";
			empByDept(deptChoice, empNames, depts, count);
			system ("pause");
			break;
			}//end else
	   case 3: //calculate the avg. salary
			cout << "Average employee salary: $" << calcAvgSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 4: //calculate the lowest salary
			cout << "Lowest paid employee's salary: $" << calcLowSal(salaries, count) << endl;
			system ("pause");
			break;
	   case 9: //administrative options
			//system("cls"); //clears screen for administrative options
			cout << admin_Options(empNames, salaries, depts, count);
			break;
	   case 0: //exit
			cout << "Goodbye!\n";
			exit (3);
	   }
	   }while (choice !=0);//end do while	  
}//end main function

void empList(char **empNames, double salaries[], char **depts, int count)//lists all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;			
	}//end if
	else
	{
	cout << "Employee: " << empNames[i] << "  Salary: " << salaries[i] << "  Department: " << depts[i] << endl;
	}//end else
}//end EmpList function

void empByDept(char deptChoice, char **empNames, char **depts, int count)//list all employees assigned to a specific department
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	if (**depts == deptChoice)
	cout << "Name: " << empNames[i] << endl;
	}//end else
}//end of EmpByDept function

double calcAvgSal(double salaries[], int count)//calculates the average salary of all employees
{for (int i=0; i<count; i+=1)
  
	if (count < 1)
	{
		cout << "No Records to display. Try entering employee data first!\n";
		system ("pause");
		break;
	}//end if
	else
	{
	double avg_Sal = 0.00;
	avg_Sal = avg_Sal + salaries[i];
	return avg_Sal;
	}//end else
}//end calcAvgSal function

double calcLowSal(double salaries[], int count)//calculates the lowest salary of all paid employees
{
	if (count < 1) {
		cout << "No Records to display. Try entering employee data first!\n";
		system("pause");
		return 0.0;
	}
	
	double lowest = salaries[0];

	for (int i=1; i < count; i+=1) {
		if (salaries[i] < lowest) { lowest = salaries[i]; }
	}

	return lowest;
}//end calcLowSal function


Was This Post Helpful? 0
  • +
  • -

#14 djkaotix  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 16-November 07

Re: Values not being displayed in function

Posted 05 December 2007 - 10:00 AM

ok so.. would I need to create another array to hold the values that are found in the search and then display them out?

Can't I just code it to do a sequential search since the max # of records is 25? All I want it to do is to cout the empName if the dept search matches their dept.

I've looked at code that will count the # of reocurances, but not display the search results... how would I modify what I have so that it loops there and displays all names for the given dept.

ALSO! for some reason it's only taking my first character I type in.
Was This Post Helpful? 0
  • +
  • -

#15 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4299
  • View blog
  • Posts: 12,060
  • Joined: 18-April 07

Re: Values not being displayed in function

Posted 05 December 2007 - 12:20 PM

I have told you why it is taking only the first letter, you have deptChoice defined as char deptChoice; This means a variable that holds one character (the first character).

Secondly, your empByDept is a sequential search, you are looking through each item of the array and comparing the deptChoice to the array items, you are just doing that part incorrectly. For some reason you chose to drop your subscript on the dept array. I told you how you needed to compare dept to deptChoice, using strcmp.

You don't need to create another array to hold the matches, unless you want to do that. If you just want to print the names in the department, you can do what you are doing and print out each match as you find it. Again, your matching mechanism needs the fix. Remember, depts is an array of character strings now... you need a subscript on depts.

Follow the previous steps I outlined to you. Once you make those changes, your search by department will start working.

:)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2