//The code has a very strange bug, I'll find it later.#include<stdio.h>#include<math.h>doubleFloatsDiffDivProduct(double dNumA, double dNumB);intmain(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.doubleFloatsDiffDivProduct(double dNumA, double dNumB){double dDiff, dProduct, dResult;dDiff = fabs(dNumA - dNumB);dProduct = dNumA * dNumB;dResult = dDiff / dProduct;return(dResult);}
1 回答
哔哔one
TA贡献1854条经验 获得超8个赞
while(sStatus==2){ }这是个循环,你要是听它的话乖乖输入两个数,sStatus一直是2,会无限循环下去。我猜用if(sStatus==2)就行了。然后函数没有调用的问题,应该是没有输出吧。
- 1 回答
- 0 关注
- 179 浏览
添加回答
举报
0/150
提交
取消