The output changes with the amount of characters of the names.
Smith, John 3.50
Jones, Tom 3.50
Mincher, Fred 3.50
I have messed with it quite a bit with << left << right but it's just not working. I could right justify the names which would solve the problem. However, I would like to figure out to get it the way I want. Thank you for your time.
Ah, I think I understand. What happens if the name is over 15/20 characters? I am going to go write this up thank you. This is that same program I was working on yesterday kemort.
What happens if the name is over 15/20 characters?
You have two choices - you increase the available space (by setting a larger width), or you shorten any excess-length strings (use the substr() method).
If you wished you could find the maximum length of all strings and send it as a parameter to the output routine to include in setw(). This seems over-the-top. 20 characters ought to be plenty.
setw sets the minimum width of the next thing that is outputted. If you want the first column to contain both the last and first name you need to combine them so that you can output them with one output operation (<<).
1 2 3
cout << left << setw(15) << (lastName[j] + " , " + firstName[j]) // first column
<< right << setw(15) << gpa[j] // second column
<< endl;