You are on a 5 hour sea voyage. The ship sails at a speed of 40 km per hour. Write a program that will output how many... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

You are on a 5 hour sea voyage. The ship sails at a speed of 40 km per hour. Write a program that will output how many...

"You are on a 5 hour sea voyage. The ship sails at a speed of 40 km per hour. Write a program that will output how many kilometres the ship has traveled by each hour." Sololearn's tip: "Remember to use endl to create a new line for every iteration output." I don't know why sololearn's codecoach is marking my code wrong and yet my output and sololearn's output is the same https://code.sololearn.com/cMZ53L1EW8Xc/?ref=app

30th Dec 2020, 4:22 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
20 Answers
+ 4
You're looking for something like this? https://code.sololearn.com/cPXG3aK1hhek/?ref=app
30th Dec 2020, 4:46 PM
Simba
Simba - avatar
+ 1
iterate from 40 to 200 as said above.
30th Dec 2020, 4:47 PM
John Robotane
John Robotane - avatar
+ 1
TheWh¡teCat 🇧🇬 Simba Zatch bell John Robotane Thank you all for your help. I have gotten, I did as you said.
30th Dec 2020, 4:51 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
+ 1
#include <iostream> using namespace std; int main() { int distance = 0; //your code goes here for (distance = 40; distance <= 200; distance += 40) cout << distance << endl; return 0; }
20th Sep 2021, 5:30 PM
Malik Mehrab Rashid
Malik Mehrab Rashid - avatar
+ 1
#include <iostream> using namespace std; int main() { int t=0; while (t<=4) { t++; int d; d=t*40; cout<<d<<endl; } return 0; } different option
5th Nov 2022, 8:40 AM
Veldvar
Veldvar - avatar
0
Habeebullah Dindi , post the full description of the task, so someone can help you.
30th Dec 2020, 4:26 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
You are on a 5 hour sea voyage. The ship sails at a speed of 40 km per hour. Write a program that will output how many kilometres the ship has traveled by each hour. Remember to use endl to create a new line for every iteration output.
30th Dec 2020, 4:30 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
0
the problem could be the extra space you print. remove it and see what happens.
30th Dec 2020, 4:35 PM
John Robotane
John Robotane - avatar
0
Habeebullah Dindi , is there an input mentioned in the task, or otherwise the code should output from 40 to 200 kilometres.
30th Dec 2020, 4:35 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Don't they show any example? can you please share with us? Edit: We can see the example but it would be better if you have posted a sample input and output of that code coach.
30th Dec 2020, 4:41 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
Habeebullah Dindi 40km per hour .So first it should print the value from 40 to 200 but your code is printing 40,80 and 120 but in the description they said you have to print the output of each hour.
30th Dec 2020, 4:44 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
John Robotane I have removed the space but the problem persists
30th Dec 2020, 4:46 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
0
Zatch bell Hello, this problem doesn't require an input and in code coach solution, there was no input as well.
30th Dec 2020, 4:47 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
0
Simba Hello, this is the kind I wrote first but in coahcode's solution the stopped at "120"
30th Dec 2020, 4:49 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
30th Dec 2020, 4:50 PM
Habeebullah Dindi
Habeebullah Dindi - avatar
0
as simple as that ! #include <iostream> using namespace std; int main() { int distance = 0; int i ; cin>>distance ; for (i=1; i<=5 ;i++) cout<<40*i<<endl ; return 0; }
26th Jul 2021, 2:01 PM
Hanine
Hanine - avatar
0
i did like this: #include <iostream> using namespace std; int main() { int distance = 0; for(int hours = 0; hours <= 4; hours++){ distance += 40; cout << distance << endl; } return 0; }
8th Aug 2021, 3:39 PM
A I K A
A I K A - avatar
0
#include <iostream> using namespace std; int main() { int distance = 0; //your code goes here for(distance = 40; distance <=200; distance+=40) cout << distance << endl; return 0; }
30th Dec 2021, 3:41 AM
Pedro Alvarez
0
#include <iostream> using namespace std; int main() { int distance = 0; //your code goes here for (distance = 40; distance <= 200; distance += 40) cout << distance << endl; return 0; } Good Luck
25th Jan 2022, 11:36 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
#include <iostream> using namespace std; int main() { int distance = 0; //your code goes here for( int x = 1;x <= 5; x++) {distance += 40; cout << distance << endl;} return 0; } it gives the perfect result
7th Nov 2022, 7:37 AM
nathan richardson
nathan richardson - avatar