I am trying to create a program which read data and sorts it out, the data file contains id and grades of those ids and i am have to sort by order of grade and move the id with it, here is where i got so far but it is not working for me.
thanks in advance
Code:#include <iomanip> #include <cstdlib> #include <iostream> #include <fstream> using namespace std; int main () { int n,f,j,id[12],i; double grade[12],hold; ifstream input; for (f=0;f<12;f++) { input >> id[f]; input >> grade[f]; } for (j=0; j<12; j++) { for (i=0; i<12; i++); { if (grade[i-1] > grade[i]) { hold = grade[i]; grade [i-1] = grade[i]; grade[i] = hold; } cout << grade[i] << "\n"; } } input.close(); system ("pause"); return 0; }




Reply With Quote