hey again.
I am getting a seg-fault when I run my program but my debugger is not telling me where it is. Usually it highlights the line in blue where the code broke. I have highlighted below where the code does crash, can anyone see what I have done wrong to cause this?
Code:
#include <iostream>
#include <iomanip>
#include <string>
// function prototypes
const int getArraySize();
void getEmployeeNames ( const int& );
void getSalaryAmounts ( std::string[], const int& );
void displayResults ( std::string[], double[], double[], const int& );
// main function - driver //////////////////////////////////////////////////////
//
int main ( void )
{
std::cout << std::setprecision( 2 ) << std::fixed;
const int ARRAY_SIZE = getArraySize();
getEmployeeNames ( ARRAY_SIZE );
std::cin.get(); // freeze console output window
return 0; // return value from int main
}
// function to find out how many employees will be calculated
const int getArraySize()
{
int totalEmployee = 0;
while ( totalEmployee == 0 )
{
std::cout << "Enter total employees: ";
std::cin >> totalEmployee;
}
const int ARRAY_SIZE = totalEmployee;
return ARRAY_SIZE;
}
// function to gather the names of the employees
void getEmployeeNames ( const int &rSIZE )
{
std::cin.ignore();
std::string employeeNames[ rSIZE ];
for ( int i = 0; i < rSIZE; i++ )
{
std::cout << "Enter employee name " << i << ": ";
std::getline ( std::cin, employeeNames[ i ] );
std::cout << std::endl;
}
getSalaryAmounts ( employeeNames, rSIZE );
}
// function to calculate employee salaries
void getSalaryAmounts ( std::string empNames[], const int &rSIZE )
{
double totalProffit = 0;
double salary = 0;
double proffit[ rSIZE ];
double salaryArray[ rSIZE ];
for ( int i = 0; i < rSIZE; i++ )
{
std::cout << "Enter total proffit for " << empNames[ 0 ] << ": ";
std::cin >> totalProffit;
proffit[ i ] += totalProffit;
salary = totalProffit * 0.09 + 200;
salaryArray[ i ] += salary;
empNames++;
}
// THE CODE BREAKS HERE ///////////////////////////////////
displayResults ( empNames, proffit, salaryArray, rSIZE );
}
// function to display the results
void displayResults ( std::string empNames[], double proff[], double sal[],
const int &rSIZE )
{
std::cout << "\nEMPLOYEE NAME" << std::setw( 12 ) << "PROFFIT"
<< std::setw( 12 ) << "SALARY\n\n";
for ( int i = 0; i < rSIZE; i++ )
{
std::cout << empNames[ i ] << std::setw( 14 ) << proff[ i ]
<< std::setw( 14 ) << sal[ i ] << std::endl;
}
}