please correct my code in sorting all of the data.. if i want to sort the other input id like the other data to follow..

#include<iostream>
#include<windows.h>
#include<string.h>
#include<iomanip>
#include<conio.h>
#include<math.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
void gotoxy(int col,int line)
{
COORD coord;
coord.X=col;
coord.Y=line;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

char name[30][30],buff[30];
int a,b,c,y,x,id[30],buf,buf1,sub[30];
float grade[30];
int main()
{
gotoxy(5,2); cout<< "Name of Student";
gotoxy(25,2); cout<< "ID Number:";
gotoxy(35,2); cout<< " Subject Code:";
gotoxy(55,2); cout<< "Grade:";
gotoxy(65,2); cout<< "Remark:";
for(x=1;x<=3;x++)
{
gotoxy(5,5+x);cin>> name[x];
gotoxy(25,5+x);cin>> id[x];
gotoxy(35,5+x);cin>> sub[x];
gotoxy(55,5+x);cin>> grade[x];

if (grade[x]==1)
{
gotoxy(65,5+x);
cout << "PASSED";
}
else if (grade[x]<=3.5)
{
gotoxy(65,5+x);
cout << "PASSED";
}

else
{
gotoxy(65,5+x);
cout << "FAILED";
}

}
{
for (x=1;x<=3;x++)
{
for (y=1;y<=3;y++)
{
if (id[x]>id[y])
{
buf=id[x];
id[x]=id[y];
id[y]=buf;
(buff,name[x]);
strcpy(name[x],name[y]);
strcpy(name[y],buff);
memcpy(buf1,sub[x]);
memcpy(sub[x],sub[y]);
memcpy(sub[y],buf1);
}



}
}
}

system("cls");

gotoxy(5,2); cout<< "Name of Student";
gotoxy(25,2); cout<< "ID Number:";
gotoxy(35,2); cout<< " Subject Code:";
gotoxy(55,2); cout<< "Grade:";
for (x=1;x<=3;x++)
{
gotoxy(5,5+x); cout << name[x];
gotoxy(25,5+x); cout << id[x];
gotoxy(35,5+x);cout <<sub[x];
gotoxy(55,5+x);cout <<grade[x];

}
getch();
}

Topic archived. No new replies allowed.