C函数计算问题,我要么得到错误,要么不会在函数中执行计算



伙计们,我的代码目前有问题。我的代码是用于将delta转换为star,将star转换为delta,然后退出。然而,这并不重要,只是一点背景。因此,对于代码来说,所有的计算都必须在一个函数中完成,出于某种原因,当我要求用户输入R1、R2和R3的值,然后试图通过我的函数进行计算时,不会使用用户输入的值进行计算。我所评论的并不重要,因为这些比特可以很好地进行

下面是代码的一部分,我需要的帮助

float conversions (float RA, float R1, float R2, float R3)
{
//Star to Delta conversion
RA = ((R1*R2+R2*R3+R3*R1)/R3);

}

int main(void){
float RA,R1,R2,R3;

//printf("Please enter an S to convert Star to Delta, a D to convert Delta to Star, and Q to quit ");
//char x = UserInput();
//printf ("You selected %cn", x);


printf("Please enter a value for R1 R2 and R3 seperated by a space: ");
scanf("%f %f %f", &R1, &R2, &R3);

printf("%f %f %f", R1, R2, R3);  // test to ensure values were being passed to variables
conversions(R1,R2,R3,RA);
printf("%f", RA);
}

此代码可以帮助您

float conversions (float R1,float R2, float R3)
{
//Star to Delta conversion
return (R1*R2+R2*R3+R3*R1)/R3;
}

int main(void){
float RA,R1,R2,R3;
//printf("Please enter an S to convert Star to Delta, a D to convert Delta to Star, and Q to quit ");
//char x = UserInput();
//printf ("You selected %cn", x);

printf("Please enter a value for R1 R2 and R3 seperated by a space: ");
scanf("%f %f %f", &R1, &R2, &R3);
printf("%f %f %f", R1, R2, R3);  // test to ensure values were being passed to variables
printf("n%f",conversions(R1,R2,R3));
}

您可能想要这个:

float conversions (float R1, float R2, float R3)
{
//Star to Delta conversion
return (R1*R2+R2*R3+R3*R1)/R3;
}

并这样称呼它:

RA = conversions(R1,R2,R3);

或者这个:

void conversions (float R1, float R2, float R3, float *RA)
{
//Star to Delta conversion
*RA = ((R1*R2+R2*R3+R3*R1)/R3);    
}

并这样称呼它:

conversions(R1,R2,R3, &RA);

最新更新