ok after all of the grades and first and last names are entered, what do i need to do to get it to print the grades with the names out in order from heighest to lowest?

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std; 
const int MAX = 3;
struct Person
{
 string Firstname, Lastname;
 int grade;
 Person()
 {
  Firstname="No name assigned";
  Lastname="No name assigned";
  grade = -1;
 }
 Person (string l, string f, int g)
 {
 Firstname = f;
 Lastname =l;
 grade = g;
 }
};


int main()
{
 int x = 0; 
 while (x++ < 5)
  {
   int grade;
   string strFirstname, strLastname;
   cout <<"****************************************"<< endl;
   cout <<"Enter person's first name: ";
   getline(cin, strFirstname);
   cout <<"Enter person's last name: ";
   getline(cin, strLastname);
   cout <<"Enter the grade: ";
   cin>>grade;
   cin.ignore();
   Person p1(strLastname, strFirstname, grade);
   //cout <<"The person's name is: "
   //<<p1.Lastname<<", "<<p1.Firstname<<endl;
   //cout <<"The grade is: "
   //<<p1.grade<<endl;
   cout <<"****************************************"<< endl;
  }
  
  {
   cout <<"The grades from heighest to lowest: "<< endl;
   cout <<"****************************************"<< endl;
  }
 return 0;
}

You need to store each set of inputs in some sort of container, sort the contents of the container, then print out the sorted values. There are several containers that could be used, though for beginners arrays seem to be the most common. There are several sorting protocols that could be used, though for beginners the bubble sort seems to be pretty popular.

This article has been dead for over six months. Start a new discussion instead.