这是我的代码:
#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的原因),但是现在出现了错误。我该如何解决?谢谢!