functions and arrays

This is a discussion on functions and arrays within the C Programming forums, part of the General Programming Boards category; program to print a table, with details of a line of trucks. need to use arrays and functions. cant see ...

  1. #1
    Unregistered
    Guest

    functions and arrays

    program to print a table, with details of a line of trucks.
    need to use arrays and functions.
    cant see where i'm going wrong, can anyone help?



    #include<stdio.h>
    #define SIZE 8
    voidmain()

    void running_costs(long int[],long int[],long int[]);
    void miles_since_last(long[],long[],long[]);
    {
    int i;
    long int last_service [] = {10000,21000,33000,42000,18000,29000,59000,50000};
    long int current_mileage [SIZE];
    long int running_costs [SIZE];
    long int mileage_since_last [SIZE];


    /************************************************** ****************************/
    /* function that calculates the running costs since the last service */
    /************************************************** ****************************/
    void running_costs(long current_mileage[],long running_costs[])
    {
    for(i = 0; i < SIZE; i++)
    {
    printf("Please enter the current mileage for truck %d: ", i);
    scanf("%ld", &current_mileage[i]);
    }

    for (i = 0; i < SIZE; i++)
    {
    if (current_mileage[i] <= 20000)
    running_costs[i] = (current_mileage[i] - last_service) * 0.05;
    else
    if (current_mileage[i] <= 40000)
    running_costs[i] = (current_mileage[i] - last_service)* 0.08;
    else
    if (current_mileage[i] > 40000)
    running_costs[i] = (current_mileage[i] - last_service)* 0.1;
    scanf("%ld", &running_costs[i]);

    if (current_mileage[i] > 60000)
    printf("NEEDS REPLACING");
    }
    }

    /************************************************** ****************************/
    /*Function that calculates the Mileage since last service */
    /************************************************** ****************************/
    void miles_since_last(long current_mileage[],long last_service[],long mileage_since_last[])
    {
    for (i = 0; i < SIZE; i++)
    {
    mileage_since_last[i] = current_mileage[i] - last_service[i];
    }
    }
    /************************************************** ****************************/

    void running_costs, (current_mileage,running_costs);
    void miles_since_last, (current_mileage,last_service,mileage_since_last);

    printf("\nMileage since last service\tRunning costs\n");
    printf("****************************************** ***************\n");

    for(i = 0; i < SIZE; i++)
    {
    printf("\t%ld\t\t\t%ld\n", mileage_since_last[i], running_costs[i]);
    }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >cant see where i'm going wrong, can anyone help?
    My suggestion, throw that program away and start over, but read the textbook more closely this time. In the case of a program such as this it's better to just start over from scratch than to waste time trying to fix the problems.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. arrays, functions, HELP
    By beginner1 in forum C Programming
    Replies: 4
    Last Post: 05-20-2009, 03:29 PM
  2. Manipulating Character arrays in functions.
    By kbro3 in forum C++ Programming
    Replies: 11
    Last Post: 08-16-2008, 02:24 AM
  3. functions using arrays
    By trprince in forum C Programming
    Replies: 30
    Last Post: 11-17-2007, 05:10 PM
  4. Arrays and Functions
    By KunoNoOni in forum Game Programming
    Replies: 12
    Last Post: 10-04-2005, 09:41 PM
  5. Arrays out-of-bounds in functions only?
    By KneeLess in forum C Programming
    Replies: 5
    Last Post: 11-03-2004, 05:46 PM

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