1

this program should output the names in ascending order which entered by the user. i know there is wrong under if(strcmp...) part..because i do not how to order it...
can someone show me how to continue..
thank you..

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char name[4][50];
//char temp[50];


for (int i=0; i <=3; i++)
{
cout << "Enter student name [" << i+1 << "]: ";
cin.getline(name, 50 );
}


if ( strcmp(name, name[i+1]) > 0)
{
for (int i=0; i<4 ; i++){
//strcpy(temp,name); //not sure!!
strcpy(name[i+1],name);
//strcpy(temp,name[i+1]);
//strcpy(name[i+1],name);
}

for (int a=0; a < 4 ; a++)
cout << name[a][50] << endl;

}


else

for (int b=0; b<=3 ; b++)
cout << name<< endl;


return 0;
}

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Dave Sinkula
0

Have you done swapping of integers? The same principle applies. Make a temporary copy of a, write b to a, write the temporary copy to b. With integers, you could use simple assignment; with C-style strings, you use strcpy.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.