【发布时间】:2013-07-12 15:58:58
【问题描述】:
伙计们,我正在尝试使用带有 char 变量的“if”语句,但它似乎没有注意到何时满足“yes”条件。我不知道是否有办法在没有数组的情况下做到这一点。下面是我的代码。任何帮助深表感谢。
// Running times calculator
# include <iostream>
# include <math.h>
using namespace std;
int main ()
{
float cTime;
float gTime;
float cDist;
float gDist;
float min;
float sec;
float cMin;
float cSec;
float p1000;
char response[1];
int blank;
printf ("Welcome to the running times calculator.\n\nEnter your completed race distance in metres: \n");
scanf ("%f", &cDist);
printf("Enter your completed race time. Type minutes, hit enter. Type seconds, hit enter\n");
scanf ("%f" "%f", &cMin, &cSec);
cTime = cSec+(60*cMin);
p1000 = pow(1000/cDist,1.1)*cTime;
printf ("Would you like to enter another race time to improve prediction accuracy? \n");
scanf ("%s", &response);
if(response == "yes")
{
printf ("Enter your completed race distance in metres: \n");
scanf ("%f", &cDist);
printf("Enter your completed race time. Type minutes, hit enter. Type seconds, hit enter\n");
scanf ("%f" "%f", &cMin, &cSec);
cTime = cSec+(60*cMin);
p1000 = ((pow(1000/cDist,1.1)*cTime)+p1000)/2;
}
printf ("What is your goal race distance in metres? \n");
scanf ("%f", &gDist);
gTime = pow(gDist/1000, 1.1)*p1000;
min = gTime/60;
sec = remainder(gTime,60);
if (sec < 0)
{
sec = sec + 60;
min = min - 1;
}
printf ("Your predicted time for a race of %.0f metres is %.0f minutes and %.0f seconds", gDist, min, sec);
scanf("%f", &blank);
return 0;
}
【问题讨论】:
-
未知标识符
printf。你忘了#include <stdio.h>(或<cstdio>) -
@Borgleader:为什么这不是 C++?有没有 C++ 语言之外的语句?
-
@ThomasMatthews printf、scanf、char 数组。这是 C 代码,因此应标记为 C。
-
@Borgleader:我可以在 C++ 下编译它。 C++ 标签是否意味着问题必须使用一些 C 语言中没有的 C++ 语言元素?
-
想知道为什么他得到了
iostream...
标签: c++ if-statement char