So LOST!!!

This is a discussion on So LOST!!! within the C Programming forums, part of the General Programming Boards category; I know this is a simple program to write, but i seriously am lost...if someone could help me out... if ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    So LOST!!!

    I know this is a simple program to write, but i seriously am lost...if someone could help me out...

    if not show me the code ,at least to get me started...

    of course. if you could send me the finished project it would begreat ... since its due monday!! but if not, just some help would be greatly appreciated!! Below is the assignment...

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Write a program in C which will keep a list of employees, their first and last name, their employee number, and their salary.



    The program should be able to hold up to 30 employees. To enter the data into the program, the user will be asked for each employee to enter first name, middle initial, last name, employee number, and salary.



    Enter employee information:

    Enter employee number: 123

    Enter first name: John

    Enter middle initial: A.

    Enter last name: Smith

    Enter salary: 38471.25



    After the employee information has been entered, the program should display the information entered in the following format:



    By Employee Number:

    Employee Number
    First name
    M.I.
    Last name
    Salary

    123
    John
    A.
    Smith
    43123.25

    150
    Mary
    B.
    Jones
    48381.31

    182
    Lester
    C.
    Harris
    32100.10




    Enter selection:

    (N) List always at sorted by employee number

    (F) List sorted by first name

    (L) List sorted by last name

    (S) List sorted by salary

    (Q) Quit





    For each selection display the list in the preferred sorted order.



    By Salary:

    Employee Number
    First name
    M.I.
    Last name
    Salary

    182
    Lester
    C.
    Harris
    32100.10

    123
    John
    A.
    Smith
    43123.25

    150
    Mary
    B.
    Jones
    48381.31






    By First Name:

    Employee Number
    Employee Name:
    Salary:

    123
    John A. Smith
    43123.25

    182
    Lester C. Harris
    32100.10

    150
    Mary B. Jones
    48381.31




    By Last Name:

    Employee Number
    Employee Name:
    Salary:

    182
    Harrison, Lester C.
    32100.10

    150
    Jones, Mary B.
    48381.31

    123
    Smith, John A.
    43123.25


    Thank you for your help!!
    Drew

  2. #2
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Something along these lines, but it's been a while since I've used the struct.

    Code:
    struct employ
    {
       char name[65];
       char initial;
       char fname[30];
       char lname[30]
       long ID;
       float salary;
    };
    
    main...
    
    struct employ myemp[30];
    
    for(index=0; index < 30; index++)
    {
        fgets(myemp[index].name, 30, stdin);
        ... do similar stuff with other records
    }
    use a loop to print out the struct stuff similar to how you read it in.

    HTH
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What exactly are you stuck with? Post what you have written so far, and say specifically where your problems are.

    I know you're only joking about getting someone to complete it for you, but please don't post complete assignments, you won't get a very good response.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    diff question

    Before I ask about the previous posted problem...I have been working on this assignment to calculate the mean, std deviation, variance, smallest and largest number based on numbers the user inputs...below is what i have so far...it is pretty much complete except i cannot get the std dev , median, and var to display...i know it has to do with my printf statements..if someone could take a look and let me know what i am doing wrong it would be greatly appreciated...thank you

    Drew

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



    double totalarray(double *x, int n);
    double smallest_value(double *x, int n);
    double largest_value(double *x, int n);
    double median(double *x, int n);
    double average(double x[], int n);
    double stdeviation (double x);
    double var(double x);


    void main()
    {
    double *base, *calcarray;
    int i,n;
    double average,temp,total,smallest,largest,var, stdeviation,
    median;

    printf("\nEnter the total number of double precision floating
    point values to be entered: ");
    scanf("%d", &n);

    base =(double*) malloc (n*sizeof(double));
    if (base == NULL)
    {
    printf("\n\nMemory Allocation failure!\n\n");
    exit(1);
    }


    for (i=0; i<n; i++)
    {
    printf("\nEnter number %d: ", i+1);
    scanf("%lf", &temp);
    base[i] = temp;
    }

    calcarray =(double*) malloc (n*sizeof(double));
    if (calcarray == NULL)
    {
    printf("\n\nMemory Allocation failure!\n\n");
    exit(1);
    }


    for (i=0; i<n; i++)
    {
    printf("\nEnter number %d: ", i+1);
    scanf("%lf", &temp);
    calcarray[i] = temp;
    }



    total = totalarray(base,n);
    printf("\nThe total is %.2lf", total);

    smallest = smallest_value(base,n);
    printf("\nThe smallest is %.2lf\n\n",smallest);

    largest = largest_value(base,n);
    printf("\nThe largest is %.2lf\n\n",largest);

    average = total/n;
    printf("\nThe average is %.2lf\n\n", average);

    median =
    printf("\nThe median is %.2lf\n\n", median);

    var =
    printf("\nThe variance is %.2lf\n\n", var);

    stdeviation =
    printf("\nThe standard deviation is %.2lf\n\n", stdeviation);

    free(base);
    free(calcarray);
    }

    /******************
    total for array
    ******************/
    double totalarray(double *x, int n)
    {
    double result = 0.0;
    int i;

    for (i=0; i<n; i++)
    {
    result = x[i] + result;
    }
    return(result);
    }

    /**********************
    find smallest value
    **********************/
    double smallest_value(double *x, int n)
    {
    double result;
    int i;

    result = x[0];
    for(i=1; i<n; i++)
    {
    if(x[i]<result)
    result= x[i];
    }
    return(result);
    }

    /***********************
    find largest value
    ***********************/

    double largest_value(double *x, int n)
    {
    double result;
    int i;

    result = x[0];
    for(i=1; i<n; i++)
    {
    if(x[i]>result)
    result= x[i];
    }
    return(result);
    }

    /**********************
    median
    **********************/
    double median(double *x, int n)
    {
    double result;

    if (n%2)
    {
    result= x[n/2];
    }
    else
    {
    result= ((x[n/2] + x[n/2-1])/2);
    }
    return (result);
    }




    /****************
    bubble sort
    *****************/
    void bubble(double x[], int n)
    {
    int i, sorted;
    double temp;

    sorted = 0;
    while(!sorted)
    {
    sorted =1;
    for(i=0; i<n-1; i++)
    {
    if(x[i]>x[i+1])
    {
    temp = x[i];
    x[i] = x[i+1];
    x[i+1] = temp;
    sorted = 0;
    }
    }
    }
    }

    /*****************
    average array
    *****************/

    double average(double x[], int n)
    {
    double result = 0.0;
    result = totalarray(x, n)/n;

    return(result);
    }

    /**************************/


    double stdeviation (double x)
    {
    double deviation;
    deviation = sqrt(x);
    return(deviation);
    }

    double var(double x)

    {
    double variance, n;
    variance = totalarray(x,n)/(n-1);
    return(variance);
    }

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    easier to read

    Code:
     /* 
    
    #include <stdio.h>
    #include <math.h>
    #include <malloc.h>
    #include <stdlib.h>
    
    
    double totalarray(double *x, int n);
    double smallest_value(double *x, int n);
    double largest_value(double *x, int n);
    double median(double *x, int n);
    double average(double x[], int n);
    double stdeviation (double x);
    double var(double x);
    
    
    void main()
    {
        double *base, *calcarray;
        int i,n;
        double average,temp,total,smallest,largest,var, stdeviation, median;
    
        printf("\nEnter the total number of double precision floating point values to be entered: ");
        scanf("%d", &n);
    
        base =(double*) malloc (n*sizeof(double));
        if (base == NULL)
        {
            printf("\n\nMemory Allocation failure!\n\n");
            exit(1);
        }
    
        
        for (i=0; i<n; i++)
        {
            printf("\nEnter number %d: ", i+1);
            scanf("%lf", &temp);
            base[i] = temp;        
        }
    
        calcarray =(double*) malloc (n*sizeof(double));
        if (calcarray == NULL)
        {
            printf("\n\nMemory Allocation failure!\n\n");
            exit(1);
        }
    
        
        for (i=0; i<n; i++)
        {
            printf("\nEnter number %d: ", i+1);
            scanf("%lf", &temp);
            calcarray[i] = temp;        
        }
    
    
    
        total = totalarray(base,n);
        printf("\nThe total is %.2lf", total);
        
    	smallest = smallest_value(base,n);
        printf("\nThe smallest is %.2lf\n\n",smallest);
        
    	largest = largest_value(base,n);
        printf("\nThe largest is %.2lf\n\n",largest);
        
    	average = total/n;
        printf("\nThe average is %.2lf\n\n", average);
        
    	median = 
    	printf("\nThe median is %.2lf\n\n", median);
        
    	var = 
    	printf("\nThe variance is %.2lf\n\n", var);
        
    	stdeviation = 
    	printf("\nThe standard deviation is %.2lf\n\n", stdeviation);
    	
    	free(base);
    	free(calcarray);
    }
    
    /******************
    total for array
    ******************/
    double totalarray(double *x, int n)
    {
        double result = 0.0;
        int i;
    
        for (i=0; i<n; i++)
        {
            result = x[i] + result;
        }
        return(result);
    }
    
    /**********************
     find smallest value
    **********************/
    double smallest_value(double *x, int n)
    {
        double result;
        int i;
    
        result = x[0];
        for(i=1; i<n; i++)
        {
            if(x[i]<result)
            result= x[i];
        }
        return(result);
    }
    
    /***********************
     find largest value
    ***********************/
    
    double largest_value(double *x, int n)
    {
        double result;
        int i;
    
        result = x[0];
        for(i=1; i<n; i++)
        {
            if(x[i]>result)
            result= x[i];
        }
        return(result);
    }
    
    /**********************
         median
    **********************/
     double median(double *x, int n)
    {
        double result;
        
    	if (n%2)
    	{
    		result= x[n/2];
    	}
    	else
    	{
    		result= ((x[n/2] + x[n/2-1])/2);
    	}
    	return (result);
    }
    
     
    
    
    /****************
    bubble sort
    *****************/
    void bubble(double x[], int n)
    {
        int i, sorted;
        double temp;
    
        sorted = 0;
        while(!sorted)
        {
            sorted =1;
            for(i=0; i<n-1; i++)
            {
                if(x[i]>x[i+1])
                {
                    temp = x[i];
                    x[i] = x[i+1];
                    x[i+1] = temp;
                    sorted = 0;
                }
            }
        }
    }
    
    /*****************
     average array
    *****************/
    
    double average(double x[], int n)
    {
        double result = 0.0;
        result = totalarray(x, n)/n;
    
        return(result);
    }
    
    /**************************/
    
    
    double stdeviation (double x)
    {
    	double deviation;
    	deviation = sqrt(x);
    	return(deviation);
    }
    
    double var(double x)
    
    {
    	double variance, n;
    	variance = totalarray(x,n)/(n-1);
    	return(variance);
    }
    
    
    
     */

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Use code tags please.

    >> var = printf("\nThe variance is %.2lf\n\n", var);
    What are you trying to do there? var is a function, not a variable.

    >>void main
    This is in the FAQ.


    [edit]
    Threads merged to keep things kinda tidy.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Your variable declarations should look similar to this:

    double average,temp,total,smallest,largest,var, st_deviation, median;

    Your function calls should look similar to this:
    Code:
        total = totalarray(base,n);
        printf("\nThe total is %.2lf", total);
        
        smallest = smallest_value(base,n);
        printf("\nThe smallest is %.2lf\n\n",smallest);
        
        largest = largest_value(base,n);
        printf("\nThe largest is %.2lf\n\n",largest);
        
        average = total/n;
        printf("\nThe average is %.2lf\n\n", average);
        
        median = find_median(base,n);
        printf("\nThe median is %.2lf\n\n", median);
        
        var = variance(base);
        printf("\nThe variance is %.2lf\n\n", var);
    
        st_deviation = stdeviation(base);
        printf("\nThe standard deviation is %.2lf\n\n", st_deviation);
    However a couple of your formulas are wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The getting lost and walking in circles
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 05-07-2008, 09:53 AM
  2. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 07:13 PM
  3. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 05:18 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 12:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21