Having problem with display function (by arrays and menu-driven)

I have a general question concerning the project I am working with. So I am having a hard time displaying my text file within my sorting function, that comes at the end of my program.

I am passing my values through arrays, have tested the printing of my program but all my values do not show up, just have a blank screen.
My "read" function works fine (minor glitch with one line of data) but just can't find my trouble reading towards my sort function. Any tips/suggestions?

I have 3 functions not working right, but my main concern is the display. Again any tips/suggestions are open, thanks!

The Data I am inputting is provided above my code.
(((Moshiur Ahmed A 100001 CA 90805 40 12.50
Tasmia Amaat B 100002 CA 90706 35 25.60
Victor Barboza C 100003 CA 90706 42 30.00
Carlos Detorres D 100004 CA 90804 50 20.45
Tyree Ek E 100005 CA 90755 A60B 15.60
Amine El-Maziati F 100006 CA 90815 20 9.75
Loubna El-Maziati G 100007 CA 90815 25 10.50
Theresa Eyssallenne H 100008 CA 90715 40 20.00
Craig Griffith I 100009 CA 90804 40 45.00
Rodney Hallett J 100010 CA 90808 43 25.25
Andrew Hegstrom K 100011 CA 90808 45 13.50
Corey James L 100012 CA 90815 40 20.00
Farsio Kottab M 100013 CA 90755 40 20.00
Peter Lon N 100014 CA 90755 40 60.00
Joseph Lopes O 100015 CA 90808 50 100.00
Arley Lozada P 100016 CA 90280 50 30.40
Ana Moreno Q 100017 CA 90805 55 14.50
Chris Myers R 100018 CA 90802 57 30.00
Thanakom Paiboolsilp S 100019 CA 90805 56 45.75
Leonardo Priego T 100020 CA 90703 77 23.00
Evel Sanchez U 100021 CA 90806 48 12.50
Ruben Santacruz V 100022 CA 90813 40 20.00
John Ung W 100023 CA 90806 40 25.00
Fady Attia X 100024 CA 90706 40 28.00
Sopha Dip Y 100025 CA 90713 40 28.00
Ricky Reed Z 100026 CA 90221 40 11.50
Julio Umana A 100027 CA 90221 40 60.00
Rin Ran B 100028 CA 90808 47 22.45
Faycal Ferhat C 100029 CA 90814 25 BADDATA65.00
Habtom Tesfazghi D 100030 CA 90808 40 35.00)))

#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>
#include <vector>
#include <iomanip>
using namespace std;

void header();
void readRecords(ifstream& in, string[], string[], char[], int[], string[], int[], double[], double[]);
void displayRecords(ifstream& in, string[], string[], char[], int[], string[], int[], double[], double[], double[], int);
void sortRecords(ifstream& in, string[], string[], char[], int[], string[], int[], double[], double[], int);
void userLogIn(string, int, int);
int main()
{
const int size = 30;
bool flag = bool();
int selection = 0;

string firstName[30] = {""};
string lastName[30] = {""};
char mi[30] = {""};
int employeeID[size] = {0};
string state[30] = {""};
int zipCode[size] = {0};
double hoursWorked[size] = {0};
double ratePerHour[size] = {0};
double totalSalary[size] = {0};
string userName=string();
int password =0;

ifstream in;
ofstream out;

userLogIn (userName, password, size);

while(true)
{

system("cls");
header();
cout << "\n\n"<< endl;
cout << "\t\t\tM A I N M E N U" << endl;
cout << "\t\t\t=================" << endl;
cout << endl << "\t\t\t1. READ EMPLOYEE RECORDS" << endl;

cout << "\t\t\t2. SAVE PROCESSED RECORDS-FILES" << endl;
cout << "\t\t\t3. DISPLAY RECORDS" << endl;
cout << "\t\t\t4. SEARCH RECORDS" << endl;
cout << "\t\t\t5. SORT RECORDS" << endl;
cout << "\t\t\t6. EXIT" << endl;

cout << "\n\n\t\t\tPlease choose your selection: ";
cin >> selection;

if(cin.fail())
{
cout << "Invalid selection, please check your error and Try Again" << endl;
cin.clear();
cin.ignore(1000,'\n');
}
if (selection == 1)
{
readRecords(in, firstName, lastName, mi, employeeID, state, zipCode, hoursWorked, ratePerHour);
}
else if (selection == 3)
{
displayRecords(in, firstName, lastName, mi, employeeID, state, zipCode, hoursWorked, ratePerHour, totalSalary, size);

}

else if (selection == 5)
{
sortRecords(in, firstName, lastName, mi, employeeID, state, zipCode, hoursWorked, ratePerHour,size);
}

return 0;
}
}

void readRecords(ifstream& in, string firstName[], string lastName[], char mi[], int employeeID[], string state[], int zipCode[], double hoursWorked[], double ratePerHour[])
{
int i = 0;
/*char employeeData[30];*/
in.open("FinalData.txt");
bool flag= true;

while(!in.eof())
{
in >> firstName[i] >> lastName[i] >> mi[i] >> employeeID[i] >> state[i] >> zipCode[i];
{
in >> hoursWorked[i];
if(in.fail())
{
//cout << " ";
in.clear();
in.ignore(4, '\n');
(flag = true);
}
else
{
(flag= false);
}
}
(flag = true);
while(flag == true)
{
in>> ratePerHour[i];
if (in.fail())
{
//cout << " "<< endl;
in.clear();
in.ignore(1, '\n');
(flag = true);
}
else
{
(flag = false);
}
}
/*cout << fixed << setprecision(2);*/
cout << firstName[i] << " ";
cout << lastName[i] << " ";
cout << mi[i] << " ";
cout << employeeID[i] << " ";
cout << state[i] << " ";
cout << zipCode[i] << " ";
cout << hoursWorked[i] << " ";
cout << ratePerHour[i]<< "\n";
system("pause");
cout << endl;
flag= true;
i++;

}

}
void displayRecords(ifstream& in, string firstName[], string lastName[], char mi[], int employeeID[], string state[], int zipCode[], double hoursWorked[], double ratePerHour[], double totalSalary[], int size)
{
int i = 0;
int selection = 0;
int max_i= 0;
int min_i= 0;
double highestSalary=0;
double lowestSalary= 0;


cout << fixed << setprecision(2);
//system("cls");

/*for(i=0; i<30; i++) */

system("cls");
cout << "\t\t\tDisplay Records Menu" << endl;
cout << "\n\n" << endl;
cout << endl << "\t\t\t1. DISPLAY LOWEST SALARY" << endl;
cout << "\t\t\t2. DISPLAY HIGHEST SALARY" << endl;
cout << "\t\t\t3. DISPLAY TOTAL HOURS & INCOME" << endl;
cout << "\t\t\t4. DISPLAY ALL RECORDS" << endl;

cin >> selection;

totalSalary[i] = hoursWorked[i] * ratePerHour[i];

if (selection ==1)
{
totalSalary[i]=hoursWorked[i] * ratePerHour[i];
min_i= 0;
for (i=0; i<30; i++)
if (totalSalary[min_i] > totalSalary[i])
min_i=i;
lowestSalary = totalSalary[i];

cout << fixed << setprecision(2);
cout << "This is the lowest Salary attained from your records: ";
cout << lowestSalary<< endl;
system("pause");



displayRecords(in, firstName, lastName, mi, employeeID, state, zipCode, hoursWorked, ratePerHour, totalSalary, size);

}
if (selection == 2)
{
totalSalary[i]=hoursWorked[i] * ratePerHour[i];

max_i= 0;
for (i=0; i<30; i++)
if (totalSalary[max_i] < totalSalary[i])

max_i=i;
highestSalary = totalSalary[i];

cout << fixed << setprecision(2);
cout << " This is the Highest Salary attained from your records: " << highestSalary << endl;
system("pause");

}
if(selection == 4)
{
ifstream in;
in.open("FinalData.txt");
//
int i=0;
//readRecords(in, firstName, lastName, mi, employeeID, state, zipCode, hoursWorked, ratePerHour); */

//for(i=0; i<30; i++)
cout << setw(10) << left << firstName[i] << " " << setw(15) << lastName[i] << " " << setw(5) << mi[i]
<< " " << setw(10) << employeeID[i] << " " << setw(5) << state[i] << " " << setw(8) << zipCode[i]
<< " " << setw(6) << hoursWorked[i] << " " << setw(5) << ratePerHour[i];
cout << endl;

++i;
system("pause");
cout << "\nPress any key to Continue... ";

}


}
Last edited on
Topic archived. No new replies allowed.