Kes and fbody - Oh my, thanks alot..I have a working code, tested. made the changes to line 15 and 58 of my original code and outputs correctly. This is my working code for all that its worth..
#include<iostream> #include<string> using namespace std; void sortnames(string [], int); int main() { int num_of_students; int x; string name [25]; cout << "How many student" << endl; cin >> num_of_students; if (num_of_students != -1) { while (((num_of_students < 1)||(num_of_students > 25)) && (num_of_students != -1)) { cout<<"Invalid entry"<<endl; cout<<"Please enter number greater than 0 and less than 26"<<endl; cin>>num_of_students; } for (x=1; x <= num_of_students; x++) { cout << "Enter student's first name" <<endl; cin >> name[x]; } sortnames(name, num_of_students); cout << "Line formation list of names are: " <<endl; for (x=1; x <= num_of_students; x++) { cout << name[x] <<endl; } } else { cout << "Terminating......."<<endl; system("PAUSE"); return 0; } system("PAUSE"); return 0; } void sortnames(string name[], int num) { int i,a, min; string strName; for (i = 1; i <= num; i++) { min = i; strName = name[i]; for (a = i + 1; a <= num; a++) { if(name[a] < strName) { strName = name[a]; min = a; } } name[min] = name[i]; name[i] = strName; } }
Many thanks again - and excuse me for asking basic/silly questions, just learning and there is alot to process.
It looks like you are still not using name[0], and you declared string name[25] which will create locations for name[0], name[1], ... …