你好,请问为什么第24行的输入函数没有运行,函数也没有调用?

//The code has a very strange bug, I'll find it later.

#include

<stdio.h>

#include

<math.h>

double

FloatsDiffDivProduct(double dNumA, double dNumB);

int

main(void)

{

double dNum1, dNum2, dDiff, dProduct;

int sStatus;

printf_s("Enter two floats.\n");

sStatus = scanf_s("%lf %lf", &dNum1, &dNum2);

while (sStatus == 2)

{

dDiff = fabs(dNum1 - dNum2);

dProduct = dNum1 * dNum2;

printf_s("%g\n", dDiff / dProduct);

printf_s("Enter two floats.\n");

sStatus = scanf_s("%lf %lf", &dNum1, &dNum2);

}

//Call function.

printf_s("Enter another two floats.\n");

sStatus = scanf_s("%lf %lf", &dNum1, &dNum2);

printf_s("%d", sStatus);

while (sStatus == 2)

{

FloatsDiffDivProduct(dNum1, dNum2);

printf_s("Enter another two floats.\n");

sStatus = scanf_s("%lf %lf", dNum1, &dNum2);

}

getchar();

getchar();

getchar();

return(0);

}

 

//Define function.

double

FloatsDiffDivProduct(double dNumA, double dNumB)

{

double dDiff, dProduct, dResult;

dDiff = fabs(dNumA - dNumB);

dProduct = dNumA * dNumB;

dResult = dDiff / dProduct;

return(dResult);

}

慕莱坞森
浏览 183回答 1
1回答

哔哔one

while(sStatus==2){ }这是个循环,你要是听它的话乖乖输入两个数,sStatus一直是2,会无限循环下去。我猜用if(sStatus==2)就行了。然后函数没有调用的问题,应该是没有输出吧。
打开App,查看更多内容
随时随地看视频慕课网APP