将鼠标悬停在问题上时与预期">"相关的代码错误

Error in code pertaining to Expected a '>' when hovering over issue

本文关键字:gt 错误 代码 悬停 鼠标 问题      更新时间:2023-10-16
#include <iostream>
using namespace std;
int main()
{
int height, time, count;
double CONST g = 9.8, distance;
cout << "Enter number of seconds the watermelon falls: ";
cin >> time;
cout << "Enter height of bridge: ";
cin >> height;
while (distance < height && count <= time)
{
distance = 0.5 * g * count * count;
cout << count << distance;
count++;
}

}

问题是while语句在单词"time"后面的括号后面,当它悬停在上面时,它说"expected a'>'"。除了使用不同的循环之外,我不确定如何解决这个问题。我是不是错过了什么遗忘的东西?使用Visual Studio Community 2017 IDE C++制作

您的问题都在这一行:double CONST g = 9.8, distance;

首先,CONST不是(!(保留的c++字。如果您的g变量是常量,则应该使用const:

double const g = 9.8, distance;

但是这一行也不能编译,因为所有的const变量都必须立即初始化。正如double const类型下提到的distance,编译器期望其初始化。

我想,你的意思是让她成为普通的double变量:

double const g = 9.8;
double distance;

现在代码编译没有任何问题(证明(。