Thread: Values are not calculating?

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    8

    Values are not calculating?

    Finally got a programme partially working, could anyone advise why the values are not showing? Is this down to incorrect formula or i havent declared the values etc?

    Code:
    #include <stdio.h>
    #include <math.h>
    
    float timeconstant(float R, float C);
    
    float R;
    float C;
    float time_c;
    double const V1 = 0.35;
    double const V2 = 0.75;
    double const V3 = 0.95;
    float cap_c_formula;
    float cap_charge1(float R1, float C1, int V1);
    float cap_charge2(float R1, float C1, int V2);
    float cap_charge3(float R1, float C1, int V3);
    
    int main(void)
    {
    
    printf("State a Value For The Resistor?\n");
    scanf("%f",&R);
    printf("State a Value For The Capacitor?\n");
    scanf("%f",&C);
    time_c = timeconstant(R,C);
    printf("Time to Charge the Capacitor to 35 Percent : %f \n" ,cap_charge1);
    printf("Time to Charge the Capacitor to 75 Percent : %f \n" ,cap_charge2);
    printf("Time to Charge the Capacitor to 95 Percent : %f \n" ,cap_charge3);
    
    getchar();
    getchar();
    
    }
    float timeconstant(float R1, float C1)
    {
    float t_constant;
    t_constant = R1*C1;
    return t_constant;
    }
    float cap_charge1(float R1, float C1, int V1)
    {
        float capc_charge1;
        capc_charge1 = -(R1*C1)*log(V1);
    }
    float cap_charge2(float R1, float C1, int V2)
    {
        float capc_charge2;
        capc_charge2 = -(R1*C1)*log(V2);
    }
    float cap_charge3(float R1, float C1, int V3)
    {
        float capc_charge3;
        capc_charge3 = -(R1*C1)*log(V3);
    }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    You compiled it and got nothing??

    Here's what I got (by enabling -Wall flag)
    Code:
    px.c: In function ‘main’:
    px.c:25:1: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float (*)(float,  float,  int)’ [-Wformat]
    px.c:26:1: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float (*)(float,  float,  int)’ [-Wformat]
    px.c:27:1: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float (*)(float,  float,  int)’ [-Wformat]
    px.c: In function ‘cap_charge1’:
    px.c:41:11: warning: variable ‘capc_charge1’ set but not used [-Wunused-but-set-variable]
    px.c: In function ‘cap_charge2’:
    px.c:46:11: warning: variable ‘capc_charge2’ set but not used [-Wunused-but-set-variable]
    px.c: In function ‘cap_charge3’:
    px.c:51:11: warning: variable ‘capc_charge3’ set but not used [-Wunused-but-set-variable]
    px.c:53:1: warning: control reaches end of non-void function [-Wreturn-type]
    px.c: In function ‘cap_charge2’:
    px.c:48:1: warning: control reaches end of non-void function [-Wreturn-type]
    px.c: In function ‘cap_charge1’:
    px.c:43:1: warning: control reaches end of non-void function [-Wreturn-type]
    px.c: In function ‘main’:
    px.c:32:1: warning: control reaches end of non-void function [-Wreturn-type]
    /tmp/ccDqiD4u.o: In function `cap_charge1':
    px.c:(.text+0xe5): undefined reference to `log'
    /tmp/ccDqiD4u.o: In function `cap_charge2':
    px.c:(.text+0x10f): undefined reference to `log'
    /tmp/ccDqiD4u.o: In function `cap_charge3':
    px.c:(.text+0x139): undefined reference to `log'
    collect2: ld returned 1 exit status
    cap_charge1 function and the 2,3 have arguments, but when you call them in the printfs, you don't pass any arguments to them!
    Moreover, the body of them calculate something they store in a local variable. In the timeconstant you nicely return something.
    Are you confused with the name of the function and the name of the variable? Don't! They are not the same.
    Check this simple example in functions in C.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Nov 2013
    Posts
    8
    Thank you very much, shortly after posting this i just started fresh, and re wrote the code from the one i posted above, i went through step by step and realized i had too many things happening without it being clear, i now got it working perfectly!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 07-27-2013, 10:20 AM
  2. Calculating the lowest and highest values
    By Charak in forum C Programming
    Replies: 8
    Last Post: 01-30-2011, 09:57 PM
  3. Calculating min and max values of an arbitrary mesh.
    By psychopath in forum Game Programming
    Replies: 12
    Last Post: 04-21-2006, 11:33 AM
  4. help storing and calculating hex values
    By anzas in forum C++ Programming
    Replies: 4
    Last Post: 07-14-2003, 01:41 PM
  5. Replies: 2
    Last Post: 10-31-2002, 07:27 PM