0
C++ Bon voyage task - how to get rid of initial 0 output
So I am trying to complete the bon voyage task in C++. My code is below. #include <iostream> using namespace std; int main() { int distance = 0; int speed = 40; for (int time = 0; time <=5; distance = speed * time){; time +=1; cout << distance << endl; } return 0; } My output is 0 40 80 120 160 200 The app is looking for that output without the initial 0 output. How would I am end my code to avoid the initial 0 output. I got around it by adding an if (distance >0) but I feel there must be a better way to do it. Thanks.
2 Respostas
+ 1
Make time equal 1
time = 1
0
And also make distance=0 ....(int distance=40;)