Thread: little help

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Question little help

    why wont this work


    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>

    typedef struct list_data LD;

    struct list_data
    {

    int id;

    int wage;

    int sex;

    int age;

    };



    int arrange_id(const void *e1, const void *e2)

    {

    LD *a1=(LD *)e1;
    LD *a2=(LD *)e2;

    return (a1->id - a2->id);

    }

    int arrange_wage(const void *e1, const void *e2)

    {

    LD *a1=(LD *)e1;
    LD *a2=(LD *)e2;

    return (a1->wage - a2->wage);

    }

    int arrange_age(const void *e1, const void *e2)

    {

    LD *a1=(LD *)e1;
    LD *a2=(LD *)e2;

    return (a1->age - a2->age);

    }


    int main (void)
    {
    int b, i;

    LD a[10],

    char sort;


    printf("please enter the number of people that you wish to enter\n");
    scanf("%d",&b);
    printf("The number of people you will enter is =%d\n\n", b);

    printf("Now enter the data\n\r");

    for (i=0; i<b; i++)
    {

    printf("please enter the ID of (person %d)\n", i);
    scanf("%d",&a[i].id);
    printf("please enter the Wage of (person %d)\n", i);
    scanf("%d",&a[i].wage);
    printf("please eter the Sex,(0 for male, 1 for female) of (person %d)\n", i);
    scanf("%d",&a[i].sex);
    printf("please enter the Age of (person %d)\n", i);
    scanf("%d",&a[i].age);


    }
    printf("thank you the data will now be put into a table\n\r");
    printf("Results\n\r");
    printf("___________________________________\n\r");
    printf("ID\t");
    printf("Wage\t");
    printf("Sex\t");
    printf("Age\t\n\r");

    for (i=0; i<b; i++)
    {
    printf("%d\t",a[i].id);
    printf("%d\t",a[i].wage);
    printf("%d\t",a[i].sex);
    printf("%d\t\n",a[i].age);
    }

    char sort;
    int t;
    t=1;
    while(t==1)
    {
    printf("How would you like to sort the inputted data?\n\r");
    printf("If you want to sort ascending by ID, type 'a'\n\r");
    printf("if you want to sort ascending by Wage, type 'b'\n\r");
    printf("if you want to sort ascending by age, type 'c'\n\r");
    printf("if you want to sort only females, type 'd'\n\r");
    printf("if you want to sort only males type 'e'\n\r");
    scanf("%c",&sort);

    if(sort==a)
    {
    qsort(a, b, sizeof(LD), arrange_id);
    }
    else
    {
    if(sort==b)
    {
    qsort(a, b, sizeof(LD), arrange_wage);
    }
    else
    {
    if(sort==c)
    {
    qsort(a, b, sizeof(LD), arrange_age);
    }
    else
    {
    if(sort==d)
    {
    /*insert sort here*/
    }
    else
    {
    /*insert sort here*/
    }
    }
    }
    }

    printf("would you like sort again\n '1' = yes\n '2' = no\n\r");
    scanf("%d",&t);
    }

    return 0;

    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No one wants to read a mass of jumbled code with no description of what it does, what it is supposed to do, where you're having problems, etc, to just take random guesses at your problem, or to rewrite your code.

    If you want help, do the following:

    1) Describe what you want the program to do.
    2) Describe what it does.
    3) Describe any errors or problems it has.
    4) Describe describe describe!

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Exclamation describe

    its a sorter.
    you put in the number of people in a table with the headings of id,age,sex,wage then when you have inputted the data it displays it.
    it follows by asking it how you want to sort the data then you type in the letter and it sorts and displays the table and asks you to sort again.....

    ignore the last two sorts where insert sort here is labbelled as i am going to do this latter

    i am a newbie so to this forum so i don't really know what i am doing

Popular pages Recent additions subscribe to a feed