// aug5ex1.cpp : Defines the entry point for the console application.
// Sort Example
// SOrt gpa's - up to 100 students.  Stop on negative num input (trailer)

#include "stdafx.h"
#define maxstu 100

int main(int argc, char* argv[])
{   float gpa[maxstu];  
    float this_gpa, hold_gpa;
	int  stu, pos, left, right;

	printf("Please type up to %d gpas.  Type negative to stop\n", maxstu);

    stu=0;
	scanf("%f", &this_gpa);

	while (  (this_gpa>= 0.0) && (this_gpa<= 4.0) && (stu < maxstu)   )   {
		stu++;    /* count the student - also his or her subscript in the array */

		gpa[stu-1] = this_gpa;

	    scanf("%f", &this_gpa);
	} /* end while  */

    printf("\nHere is the array UNsorted: \n");
	for (pos=0; pos < stu; pos++)
		printf("Student # %d had gpa of %4.2f \n", pos+1, gpa[pos]);

    for (left=0; left < stu-1; left++)
		for (right=left+1; right < stu; right++)
			if ( gpa[left] > gpa[right] ) {     /* if true, exchange the blocks */

				  hold_gpa = gpa[left];
                  gpa[left] = gpa[right];
				  gpa[right] = hold_gpa;

			}

    printf("\n\nHere is the array SORTED: \n");
	for (pos=0; pos < stu; pos++)
		printf("Student # %d had gpa of %4.2f \n", pos+1, gpa[pos]);	

	return 0;
}