Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
//The following is a function that sorts a students data according to the score that got. So I first try to sort the temp array created but the output is just 0.000000 for each loop. //
Objective-C
void sortbyscore(int entry,char name[entry][19],char surname[entry][19],float score[entry])
{
float temp[entry],tempvar;
int i,j;
for(i=0;i<entry;i++)>
	{
	temp[i]=score[i];
	}
for(i=0;i<entry-1;i++)>
	{
	for(j=0;j=entry-i-1;j++)
		{
		if(temp[j]<temp[j+1])>
			{
			tempvar=temp[j];
			temp[j]=temp[j+1];
			temp[j+1]=tempvar;
			}
		}	
	}
for(i=0;i<entry;i++)>
	{
	printf("%f",&temp[i]);
	}
}
Posted
Updated 31-Mar-15 18:10pm
v2
Comments
Mehdi Gholam 31-Mar-15 23:50pm    
Use a debugger and find out why.

Start by looking at the values in the score array, and the size of the entry value.
Add this code at the start of the function:
C++
printf("%d\n",&entry);
for(i=0;i<entry;i++)>
    {
    printf("%f\n",&score[i]);
    }

If that all looks good, use the debugger to follow your code through and look at what exactly happens in your loops.
 
Share this answer
 
Your program is not suppose to end at all.
your nested for loop condition is invalid.
C++
j=entry-i-1
//it should be 
j<entry-i-1>

</entry-i-1>


i guess this can be copy paste error.

But getting 0.00000000 is printf function is not correct.
it should be
C++
for(i=0;i<entry;i++)>
	{
//	printf("%f",&temp[i]);
        printf("%f",temp[i]);
	}
 
Share this answer
 
Quote:
for(i=0;i<entry-1;i++)>
{
for(j=0;j=entry-i-1;j++)
{

change to
C
for(i = 0; i < entry-1; i++)
{
  for(j = i+1; j < entry; j++)
  {
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900