Can anyone help me with this sort?

So i've made an alphabetical sort, and after using it and trying to get it to print the new values, all the values are blank. Maybe someone can help me figure out what i'm doing wrong here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <string>
#include <fstream>
using namespace std;


struct employee
{
       string fname;
       string lname;
       double hours;
       double rate;
       int age;
       double basewage;
       double tax;
       double wage;
};

void namesort(employee [], int);
int main()
{

    ifstream infile;
    infile.open("Homework 3 datafile.txt");
    int i, k, maxage = 0, minage = 0;
    double overwage, maxtax = 0, overtime;
    string option, taxname;
    cout << "Miser Corporation Payroll" << endl;
    
    cout << "Will data be inputted through a file? (respond with 'yes' or 'no')" << endl;
    cin >> option;
    cout << "How many employees are in the company?" << endl;
    cin >> i;
    employee emp[i];
    if (infile.is_open())
    if (option == "no"){
               for (k = 0; k < i; k++){
                                  cout << "Enter Employee First Name" << endl;
                                  cin >> emp[k].fname;
                                  cout << "Enter Employee Last Name" << endl;
                                  cin >> emp[k].lname;
                                  cout << "Enter Hours Worked" << endl;
                                  cin >> emp[k].hours;
                                  cout << "Enter Rate of Pay" << endl;
                                  cin >> emp[k].rate;
                                  cout << "Enter age" << endl;
                                  cin >> emp[k].age;}}
    else if (option == "yes"){
         for (k = 0; k < i; k++){
             infile >> emp[k].fname;
             infile >> emp[k].lname;
             infile >> emp[k].hours;
             infile >> emp[k].rate;
             infile >> emp[k].age;
             if (minage == 0)
                minage = emp[k].age;
             else if (minage > emp[k].age)
                  minage = emp[k].age;
             if (maxage < emp[k].age)
                maxage = emp[k].age;}}
    
    for (k = 0; k < i; k++){
        if (emp[k].hours > 40){
           overtime = emp[k].hours - 40;
           emp[k].wage = 40 * emp[k].rate;
           overwage = overtime * (emp[k].rate * 1.5);
           emp[k].wage += overwage;}
        else
            emp[k].wage = emp[k].hours * emp[k].rate;
        cout << emp[k].fname << " " << emp[k].lname << endl << emp[k].hours << "   " << emp[k].rate << "   " << emp[k].age << "   " << emp[k].wage << endl;}
            
    for (k = 0; k < i; k++){
        if (emp[k].age > 55)
           emp[k].tax = emp[k].wage * .5;
        else
            emp[k].tax = emp[k].wage * .1;
        if (maxtax < emp[k].tax){
           maxtax = emp[k].tax;
           taxname = emp[k].lname;}}
           cout << "The highest amount of tax paid was: " << maxtax << " by " << taxname << endl;
            

namesort(emp, i);
    for (k = 0; k < i; k++){
        cout << emp[i].fname << endl;}
               
system("PAUSE");  
return 0;
}

void namesort(employee emp[], int n){
     for (int pass = 0; pass < n-1; pass++){
         {int small = pass;
         
         for (int i = pass +1; i<n; i++){
             if (emp[i].fname < emp[small].fname)
             {small = i;}
             }
         employee temp = emp[pass];
         emp[pass] = emp[small];
         emp[small] = temp;
         }
}         }
when the cout call comes after the namesort function, i get this:
(the female gender symbol) ---two alt code lines 1D ---- 01triangle0 --- 8.90212e-306
that, 12 times.

Really need some help with this
closed account (D80DSL3A)
Wrong array index line 85. I'm sure you meant emp[k].fname not emp[i].fname
You really couldn't see that?
i didn't notice it until just a minute before you posted that.
I do feel stupid.
closed account (D80DSL3A)
Sorry. I guess a 2nd pair of eyes is needed sometimes. I've made many such errors and then looked right past it for hours.
Did that fix the problem?
EDIT: I guess it did. I now see the green checkmark.
Last edited on
Topic archived. No new replies allowed.