Thread: Developing an enhancement to existing program... with errors.

  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    17

    Developing an enhancement to existing program... with errors.

    I had written, with considerable help from this forum, a program the computes the vapor liquid equilibria of a mixture. Now adding a second part that uses the VLE arrays to compute various 'states' of the distillation process over time. That's the big picture.


    To start I need a function(s) to relate a known interpolated value from one array to other arrays. The first step to find the interpolating multiplier has several errors I need some help with. Please note that I entered a subset of the boiler_abv[] values. The true arrays contain 101 elements.


    Code:
    #include <stdio.h>
    
    
    
    
    /***************************************************/
    /*Declare*/
    double interpolate_array(double *boiler_abv, size_t boiler_abv_len, float start_abv);
    
    
    
    
    int main()
    {
    float start_abv = 0.10;
    
    
    double boiler_abv[10] =
    {
       0, 0.032, 0.062, 0.092, 0.12, 0.147, 0.174, 0.199, 0.224, 0.248
    };
    
    
    float interp_factor = interpolate_array(boiler_abv[], sizeof(boiler_abv) / sizeof(boiler_abv[0]), start_abv);
    
    
    printf("interp factor = %f", interp_factor);
    
    
    getch();
    return (0);
    }
    
    
    /*****************************************************/
    /*Definition*/
    double interpolate_array(boiler_abv[], size_t boiler_abv_len, start_abv)
    {
    int i;
    float interp_factor = 1.0;
    
    
        for(size_t i = 0; i < boiler_abv_len; i++)
        {
            if(boiler_abv[i] == start_abv)
            {
             return interp_factor;
             break;
            }
    
    
    
    
             else if boiler_abv[i] > start_abv
             {
              hi = boiler_abv[i];
              low = boiler_abv[i-1];
              interp_factor = 1 + (start_abv - low)/(hi - low);
              return interp_factor;
             }
    
    
          }
    }

    |19|error: expected expression before ']' token|
    This one I don't get. The whole line is an expression. Last time I had this error it was a malformed return statement.


    |19|error: too few arguments to function 'interpolate_array'|
    I think I describe 3 arguments to the declaration, definition, and call. ???
    |6|note: declared here|


    |23|warning: implicit declaration of function 'getch' [-Wimplicit-function-declaration]|
    How do you 'pause' for viewing? I get the same warning if I use System (pause).


    |12|warning: unused variable 'start_abv' [-Wunused-variable]|
    Unused???


    |29|error: unknown type name 'boiler_abv'|
    |29|error: unknown type name 'start_abv'|
    Thought I was clear on what 'type' means: array, float etc.


    Maybe one of those things that one simple goof up causes all errors? Just not seeing it. Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,542
    > float interp_factor = interpolate_array(boiler_abv[], sizeof(boiler_abv) / sizeof(boiler_abv[0]), start_abv);
    You don't need the [] on the first parameter.

    > How do you 'pause' for viewing? I get the same warning if I use System (pause).
    system() is prototyped in stdlib.h

    > double interpolate_array(boiler_abv[], size_t boiler_abv_len, start_abv)
    The third parameter needs a type.

    > else if boiler_abv[i] > start_abv
    This needs ( ) around the if expression.

    With so many
    return interp_factor;
    your loop isn't going to do much.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2020
    Posts
    17
    Thanks much. Appreciate the help.

    Looks like I got a little sloppy but also learned a couple things. Works now. For loop also needed to define low and high but does return the correct value under both conditions.

    Thx again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Developing a C program - Pokemon
    By water lily in forum C Programming
    Replies: 19
    Last Post: 11-28-2016, 03:39 PM
  2. Developing a C program - Pokemon
    By water lily in forum General AI Programming
    Replies: 0
    Last Post: 11-18-2016, 08:15 PM
  3. Incorporate an existing program into another?
    By thetinman in forum Windows Programming
    Replies: 5
    Last Post: 06-06-2008, 08:40 AM
  4. [WinAPI] Developing a color customizable program
    By Templario in forum Windows Programming
    Replies: 6
    Last Post: 02-04-2003, 06:12 PM
  5. help me in developing a good anti virus program
    By sadat in forum C++ Programming
    Replies: 3
    Last Post: 04-04-2002, 02:09 PM

Tags for this Thread