“表达式必须具有整数或无作用域的枚举类型”如何解决?

时间:2019-11-01 14:37:32

标签: c++

这是我的代码:

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main( )
{
    int d;
    const int g = 9.8;
    const int t = 10;

    cout << "enter time: " << endl; 

    d = 1.0/2 * g * t^2; // the error "expression must have integral or unscoped enum type" is here

    cout << "distance = " << d << endl;


    return 0;

我是C ++的新手,所以我们将不胜感激。我知道1/2将是1,因为它将是一个int类型,但是我希望1/2实际上是.5(所以这就是我执行1.0 / 2的原因),但是现在出现了错误。我该如何解决?谢谢!

0 个答案:

没有答案