0

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?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by abhimanipal
0

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

Edited by abhimanipal: n/a

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.