C++ Bon voyage task - how to get rid of initial 0 output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

5th Feb 2021, 12:28 AM
Patrick Millican
Patrick Millican - avatar
2 Answers
+ 1
Make time equal 1 time = 1
5th Feb 2021, 3:41 AM
bob
bob - avatar
0
And also make distance=0 ....(int distance=40;)
8th Oct 2021, 10:16 AM
Ashish Bostan