# Thread: Problems passing parameter to function

1. ## 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("&#37;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. Forgot to actually define Z and Theta as float, master5001. And change return type of functions to float.

3. Better yet, there is no reason to use superfluous variables anyway.

4. Unless the function returns an int type

5. 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. ## 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;
}