Im trying to make a program that will sort the the list according to its cost...from least to expensive...

here's my code:

#include <stdio.h>
#include <string.h>



typedef struct resto RESTO;

struct resto{
       char *name;
       char *address;
       float cost;
       char *food;
       };
       
void output(RESTO r1);
       
int main()
{
    RESTO r1= {"Coras","Agora",60,"BBQ"};
    RESTO r2= {"Panagatan","Opol",120,"BBQ"};
    RESTO r3= {"Max","Divisoria",70,"BBQ"};
    RESTO r4= {"XU Resto","Bukid",1200,"BBQ"};
    RESTO r5= {"Hubo2x","Eng'g Bldg. XU",6000,"BBQ"};  
    
    RESTO *ptr_r1 = &r1;
    
    output(r1;
    
    getchar();
    getchar();
}

void output(RESTO r1)
{
     printf("\n");
     printf("Name: %s\n"
            "Addr: %s\n"
            "Cost: %.2f\n"
}

can u help me with this pls?

Make an array of the restaurant structures
Then sort according to the cost or what ever criteria that you want. You can use any of the common sorting algorithms for this
Only remember that each time that you swap, swap the entire structure and not just the cost

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.