if (cSort == 'f' || 'F')
//sort by first name
//print info to screen
else if (cSort == 'l' || 'L')
//sort by last name
//print info to screen
else
//sort by score
//print info to screen
this is the first problem. each of these will evaluate like this:
- Code: Select all
if ( (cSort == 'f') || ('F') )
//sort by first name
//print info to screen
else if ( (cSort == 'l') || ('L') )
//sort by last name
//print info to screen
else
//sort by score
//print info to screen
notice the added parentheses. for what you want, you should use something like:
- Code: Select all
if (cSort == 'f' || cSort == 'F')
//sort by first name
//print info to screen
else if (cSort == 'l' || cSort == 'L')
//sort by last name
//print info to screen
else
//sort by score
//print info to screen
or:
- Code: Select all
#include <cctype>
if (toupper(cSort) == 'F') // toupper returns value of cSort as a capital letter
//sort by first name
//print info to screen
else if (toupper(cSort) == 'L')
//sort by last name
//print info to screen
else
//sort by score
//print info to screen
----------
to really simplify this, it would be better to implement a class for the students with the names and score as different member data. also using strings (#include <string>) for the names would also vastly improve things; right now names are limited to 14 characters (saving the 15th for '\0').
----------
since you are only dealing w/ two students (right now) sorting isnt too bad.
to sort by score, find which has the higher (or lower) value and save its index in a temporary variable. then output the variables (using your saved index) in the print code.
to sort by name, you'll probably have to come up with a sorting function as things currently stand. i believe, however, that the string class has built-in comparison operators. but if you dont use strings here's an idea of what to do: compare the first letter of each name (first or last depending on user's choice). if they are the same, compare the next and repeat this and what follows as necessary. if the values are different use the temp variable to store the index of which one comes first (or last) and then output similarly to above.
-----------
this was kinda long, but i hope it helped out a bit... if you need more help, just ask again
