У меня есть программа на C++, написанная в Microsoft Visual Studio (я только начал изучать). Вот мой код:Переменная, объявленная за пределами цикла, не определена внутри C++
else
// time is in seconds
int time = 0;
double speed = 0.0;
while (height >= 0)
{
cout << "At " << int time << " secs the ball is at height: " << height << " metres.\n";
time++;
height -= distanceTravelled(speed);
speed += gravity;
}
// If height dropped from positive to negative in one second, the final fraction of a
// second before it hits the ground isn't displayed - so the if statement
if (height <= 0)
cout << "At " << time << " secs the ball is at height: " << height << " metres.\n";
Когда я пытаюсь построить его я получаю сообщение об ошибке
«время» является необъявленный идентификатор.
Но я объявил это вне цикла while. Так почему его нельзя найти?
Is '<< int time <<' фактическая часть кода? Что он должен делать? – stefaanv