CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 22

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    35

    Newbie learning sorting algorithms and arrays

    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;
    }
    Last edited by peste19; April 6th, 2009 at 01:56 PM. Reason: updated code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured