【问题标题】:I've just started using DEV C++ compiler. Some programs that run fine in turbo compiler are not running in Dev compiler..What to do? [closed]我刚刚开始使用 DEV C++ 编译器。一些在 turbo 编译器中运行良好的程序在 Dev 编译器中没有运行..怎么办? [关闭]
【发布时间】:2016-01-01 18:32:44
【问题描述】:

例如,该程序在 turbo 中运行良好,但在 DEV 编译器中无法运行。请解释一下为什么。

#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
int main ()
{
int i,j,x[50],y[50],z[50],k,count=0,s;
float prb_ini,absolute_diff,prb;
y[0]=0;
prb_ini=-2;
i=0;

b:
s=0;
i=i+1;

    for(j=1;j<=6;j++)
    {
    a:
    x[j]=rand();
    y[j]=x[j]%52+1;
        for(k=0;k<j;k++)
        {
        if(y[j]==y[k])
        goto a;
        }
    if(y[j]<=26)
    z[j]=1;
    else
    z[j]=0;

    s=s+z[j];
    }
    if(s==3)
    count=count+1;

prb=(float)count/i;
absolute_diff=abs(prb-prb_ini);
if(i<=10)
goto b;
if(absolute_diff > 0.0001)
{
prb_ini=prb;

goto b;}
else
printf("\t %f ",prb);
}

我使用的是 Windows XP。但在我的大学里,他们只有 Windows 8。他们只有开发编译器。

【问题讨论】:

  • 那是因为 Turbo C++ 是古老的,从来没有能力产生可移植的 C++ 程序。
  • 如果您删除 #include &lt;conio.h&gt;,这应该使用符合标准的编译器进行编译,因为编译器通常不会给出编码风格的错误。无论如何,您似乎没有使用任何可能来自该标头的内容。
  • goto a; goto b; 我的眼睛,我的眼睛……!
  • #include &lt;conio.h&gt; 不可移植
  • @BłażejMichalik 我同意 Dev-C++ 使用的编译器已经过时,但至少它是 1998 年的标准(或接近标准)。 IDE,这是一个不同的故事,因为它是错误的。然而,在当今时代使用 Turbo C++ 是 OP 所在的任何学校都在开玩笑的玩笑。

标签: c++ dev-c++ turbo-c++


【解决方案1】:

在您看到任何输出之前,控制台窗口正在关闭。将此行添加为程序的最后一行:

printf("\t %f ",prb);
getchar();                  // <---- add this
}

编译并运行程序,然后在准备关闭控制台时按Enter

【讨论】:

  • 非常感谢!是的,它现在正在运行。 :D
  • 其实还有那个conio.h。 ..它也运行良好..
  • 那是因为你确实有一个同名的库头,但不要使用它的任何函数。
  • 'ot's functions'是什么意思?
  • 我在编辑我的打字很糟糕。
猜你喜欢
  • 1970-01-01
  • 2011-01-10
  • 2011-10-08
  • 2016-08-28
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
相关资源
最近更新 更多