Sort problem

I am trying to sort an input file with 6 lines, each having a ID number, a first and last name, and a salary. There needs to be three outputs all depending on how its sorted. The first by ID, the second by name, and the last one by salary. Right now I am having problems just sorting the Id and Salaries. The input I am using as a sample is as follows:
ID Name Salary
1000 George Washington 10000
2000 John Adams 15000
1212 Thomas Jefferson 34000
1313 Abraham Lincoln 45000
1515 Jimmy Carter 78000
1717 George Bush 80000

And When I try to sort the ID's and the salaries, It's sorting all of them except for the last one, ID 2000 and Salary 80000. Any help would be much appreciated?

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

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std; 

struct Employee{
int id;
string first;
string last;
double salary;
};

void get_data(ifstream &inp, Employee data[], int &count);
void sort_id(ifstream &inp, Employee data[], int &count);
void sort_pay(ifstream &inp, Employee data[],int &count);

int main(){
int count = 0;
string input_filename;
Employee data[100];
    
cout << "Enter the name of the file you would like to be sorted: ";
	cin >> input_filename;
	ifstream inp;
	inp.open(input_filename.c_str());
	get_data(inp, data, count);
    sort_id(inp, data, count);
    sort_pay(inp, data, count);
    
    return EXIT_SUCCESS;
}

void get_data(ifstream &inp, Employee data[], int &count){

    for (int i = 0; i < 6; i++){
	inp >> data[count].id;
	inp >> data[count].first;
	inp >> data[count].last;
	inp >> data[count].salary;
        count++;
    }
}


void sort_id(ifstream &inp, Employee data[], int &count){
    int temp = -1;
    for (int i=0; i< count; i++)
    {
        if (data[i].id > data[i+1].id){
            temp = data[i+1].id;
            data[i+1].id = data[i].id;
            data[i].id = temp;
        }
        
    }
    for (int i = 0; i < count; i++){
        cout << data[i].id << endl;
    }
}

void sort_pay(ifstream &inp, Employee data[], int &count){
    int temp = -1;
    for (int i=0; i< count; i++)
    {
        if (data[i].salary > data[i+1].salary){
            temp = data[i+1].salary;
            data[i+1].salary = data[i].salary;
            data[i].salary = temp;
                
        }
    }
    for (int i = 0; i < count; i++){
        cout << data[i].salary << endl;
    }
}
The last number being outputted is coming up as a 0.
Topic archived. No new replies allowed.