I have a program that gets first names from the user they are stored as char.
We have to then determine of the names entered which name would come first and which would come last alphabetically.
This should be accomplished with loops and if statements, we have not discussed any library functions that can accomplish this.
I am having problems with the alphabetical part of the program. Can I test 2 char variables to determine alphabetical order? Or is this best done with strings? I'm lost at this part I threw something together but it does not do what I expect/think it should do. I realize my current code would not work anyway to test the whole file, but just for trying to figure this out it just expects 2 names in the file (there can be more, but the testing won't accomplish as intended).
int main(int argc, char *argv)
cout << "How many students are there? ";
cin >> studentCount;
if(studentCount >= 1 && studentCount <= 25) //check for proper student count 1-25 allowed
for (int count = 1; count <= studentCount; count++) //ask for student names equal to the studentCount
cout << "Enter name: "; //Begin file output for n names
cin >> nameInput;
outputFile << nameInput << endl;
cout << "Invalid Input" << endl;
//inputFile >> name1; for testing make sure the names were being read correctly
//inputFile >> name2;
for (int count = 1; count <= studentCount; count++) // test as many times as there are students
inputFile >> name1; // read in 2 names from the file
inputFile >> name2;
if(name1 > name2) // test the first characters of each ??
first = name1; // if true name1 is first name2 is second alphabetically
last = name2;
first = name2; // if false name2 is first name1 is second alphabetically
last = name1;
cout << first;
cout << last;
The output for this is seemingly 2 random characters (assuming the data is not being saved to the variables).
Any insight on how to accomplish this would be appreciated, thanks.