Hi! I'm trying to figure out how to sort stuctures according to a float value called v. It almost works, but I don't completely understand it. If someone could help that would be great!

Code:

#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
typedef struct fract fract;
struct fract {
float v;
int num;
int den;
};
int cmp(const void *va, const void *vb)// compare fuction
{
return 10*(((fract*)va)->v - ((fract*)vb)->v);
}
fract val[5000];
int relprime(int a, int b)
{
if(a > b)
return 1;
if(a%2 == 0 && b%2 == 0)
return 0;
for(int i = 3; i*i <= a; i += 2)
if(a%i == 0 && b%i == 0)
return 0;
return 1;
}
int main()
{
int N,k=0;
cin >> N;
for(float i=2; i<=N; i++)
for(float j=1; j<i; j++)
if(relprime(j,i))
{
val[k].num=j;
val[k].den=i;
val[k].v=j/i;
cout << val[k].num << " " << val[k].den << " " << val[k].v << "\n";
k++;
}
cout << "\n";
qsort(val, k, sizeof(val[0]), cmp);//sorting algorithm
cout << 0 << "/" << 1 << "\n";
for(int i=0; i<k; i++)
cout << val[i].num << "/" << val[i].den << "\n";
cout << 1 << "/" << 1 << "\n";
int y;
cin >> y;
return 0;
}

Thanks a bunch.