Thread: problem with functions & for loop !

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    5

    problem with functions & for loop !

    Hi
    I'm trying to write a code that will a print a table of results
    the values of first column are known so I put them using for loop
    then i tried calling functions inside the loop to calculate the value fot the other columns
    the problem is that the third function depends on the value of the first & second functions but the values can not be sent there !
    here is the code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #define PI 3.141592653589793238462
     
    void get_values(double *, double*);
    void get_capacitance(double*, int, double);
    void get_inductance(double*, int, double);
    void get_attenuation(double,int, double, double);
    void get_attdb(double);
     
    int main(void)
    {
       double inductor, capacitor;
       int F;
       double capacitance, inductance, attenuation, attdb;
     
            
       get_values(&inductor, &capacitor);
      
       printf("L = %lf, C = %lf\n", inductor, capacitor);
      
       for (F=100;F<=1000;F=F+100)
       {
           printf("%i",F);
           printf("\t");
          
           get_capacitance(&capacitance,F,capacitor);
           printf("%lf", capacitance);
           printf("\t");
          
           get_inductance(&inductance,F,inductor);
           printf("%lf", inductance);
           printf("\t");
          
           get_attenuation(attenuation,F, inductance, capacitance);
           printf("%lf", attenuation);
           printf("\t");
          
           get_attdb(attenuation);
           printf("\t");
          
           printf("\n");
       }   
       system("PAUSE");
       return 0;
    }
     
     
    void get_values(double *L, double *C)
    {
       printf( "Please, enter the required inductor value");
       scanf("%lf", L);
            
       printf("Please, enter the required capacitor value");
       scanf("%lf", C);         
    }
     
     
    void get_capacitance(double *capacitance, int frequency, double C)
    {
        *capacitance =(((1/(2 * PI * frequency * C))));
       
    }
     
    void get_inductance(double *inductance, int frequency, double L)
    {
        *inductance = (2 * PI * frequency * L);
    }
     
    void get_attenuation(double attenuation,int F, double L, double C)
    {
         attenuation = (1/(1-(2*PI*F*2*PI*F*L*C)));
     
    }
     
    void get_attdb(double att)
    {
         printf("%lf",(20 * log10(att)));
     
    }

    thanks in advance
    Last edited by mintalbes; 04-17-2012 at 09:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using for loop and functions to create a basic menu
    By sunandstars in forum C Programming
    Replies: 2
    Last Post: 02-19-2011, 02:12 PM
  2. Replies: 2
    Last Post: 12-18-2010, 02:34 PM
  3. for loop that calls multiple functions
    By elsparko in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2009, 07:10 AM
  4. Replies: 10
    Last Post: 12-16-2008, 10:28 AM
  5. functions stops loop from running
    By a1pro in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 02:02 PM

Tags for this Thread