Problems passing parameter to function

This is a discussion on Problems passing parameter to function within the C Programming forums, part of the General Programming Boards category; Hello I wrote this simple program it accepts 2 user input parameters and returns another parameter that was calculated based ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Problems passing parameter to function

    Hello I wrote this simple program it accepts 2 user input parameters and returns another parameter that was calculated based on the user inputs. But I think my logic is wrong as it is not working.

    Code:
    int Forward_Complex_Transformation_Z(float Real, float Complex)
    {
        float Real, Complex, Z;
       
        Z = sqrt((Real*Real) + (Complex*Complex));
        
        return Z;
    }
    
    int Forward_Complex_Transformation_Theta(float Real, float Complex)
    {
        float Real, Complex, Theta;
            
        Theta = (atan(Complex / Real))*(180/pi);
        
        return Theta;
    }
    
    int main()
    {
        float baseVoltageReal,baseVoltageComplex, zVoltage,thetaVoltage;    
        printf("Enter the real part of the base voltage:\n");
        scanf("%f",&baseVoltageReal);
        
        printf("Enter the complex part of the base voltage:\n");
        scanf("%f",&baseVoltageComplex);
        
        Forward_Complex_Transformation_Z(baseVoltageReal,baseVoltageComplex);
        Forward_Complex_Transformation_Theta(baseVoltageReal,baseVoltageComplex);
        
        zVoltage = Forward_Complex_Transformation_Z();
    
        thetaVoltage = Forward_Complex_Transformation_Theta();
    
    return 0;
    }
    WHat I basically am tyring to do is send the function "Forward_Complex_Transformation_Theta" and Forward_Complex_Transformation_Z" two parameters from the main function and use the return values "Z" and "Theta".
    Code:
        zVoltage = Forward_Complex_Transformation_Z();
    
        thetaVoltage = Forward_Complex_Transformation_Theta();
    The reason why I wrote the above line is that I want to use their retuen value and assign them to another variable that i will use later in the program.

    I can't seem to get this to work any help will be good.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Forgot to actually define Z and Theta as float, master5001. And change return type of functions to float.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Better yet, there is no reason to use superfluous variables anyway.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Unless the function returns an int type

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Looking at the code in its entirety I am thinking I'd be better off just deleting the whole thing. Nothing seems to be right about that code.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    still not working

    I changed it around a little bit. I made the functions return a float and made it void so it accepts noting from other functions. But it is still not working. I don't understand why.

    Code:
        Forward_Complex_Transformation_Z(); 
        
        zBaseVoltage = Forward_Complex_Transformation_Z();
    For the above code the first line is meant to excute the function and the second line is meant to assign the return value of the excuted function to a variable called zBaseVoltage. Please point out my mistake to me as I don't understand where I am making the mistake.


    Code:
    #include <stdio.h>
    #include <math.h>
    
    float Forward_Complex_Transformation_Z(void)
    {
        float Real, Complex, Z;
        
        printf("Enter the real part of the base voltage:\n");
        scanf("%f",&Real);
        
        printf("Enter the complex part of the base voltage:\n");
        scanf("%f",&Complex);
    
        Z = sqrt((Real*Real) + (Complex*Complex));
        
        return Z;
    }
    
    float Forward_Complex_Transformation_Theta(void)
    {
        float Real, Complex, Theta;
        float pi;
        
        printf("Enter the real part of the base voltage:\n");
        scanf("%f",&Real);
        
        printf("Enter the complex part of the base voltage:\n");
        scanf("%f",&Complex);
        
        pi = 3.141592654;
        
        Theta = (atan(Complex / Real))*(180/pi);
        
        return Theta;
    }
    
    int main()
    {
        float zBaseVoltage, thetaBaseVoltage, zBaseCurrent, thetaBaseCurrent, zBaseImpedence, thetaBaseImpedence;
    ////////////////////////////////////////////////////////////////////////////////    
        Forward_Complex_Transformation_Z(); 
        
        zBaseVoltage = Forward_Complex_Transformation_Z();
        
        Forward_Complex_Transformation_Theta();
            
        thetaBaseVoltage = Forward_Complex_Transformation_Theta(); 
    ////////////////////////////////////////////////////////////////////////////////    
        Forward_Complex_Transformation_Z();
        
        zBaseCurrent = Forward_Complex_Transformation_Z(); 
        
        Forward_Complex_Transformation_Theta();
        
        thetaBaseCurrent = Forward_Complex_Transformation_Theta(); 
    ////////////////////////////////////////////////////////////////////////////////    
        Forward_Complex_Transformation_Z();
        
        zBaseImpedence = Forward_Complex_Transformation_Z(); 
        
        Forward_Complex_Transformation_Theta();
        
        thetaBaseImpedence = Forward_Complex_Transformation_Theta(); 
      
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing "this" as function parameter
    By pgavigan in forum C++ Programming
    Replies: 15
    Last Post: 07-13-2007, 10:06 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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