- 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
20 odpowiedzi
+ 4
You're looking for something like this?
https://code.sololearn.com/cPXG3aK1hhek/?ref=app
+ 1
iterate from 40 to 200 as said above.
+ 1
TheWh¡teCat 🇧🇬 Simba Zatch bell John Robotane Thank you all for your help. I have gotten, I did as you said.
+ 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;
}
+ 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
0
Habeebullah Dindi , post the full description of the task, so someone can help you.
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.
0
the problem could be the extra space you print. remove it and see what happens.
0
Habeebullah Dindi , is there an input mentioned in the task, or otherwise the code should output from 40 to 200 kilometres.
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.
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.
0
John Robotane I have removed the space but the problem persists
0
Zatch bell Hello, this problem doesn't require an input and in code coach solution, there was no input as well.
0
Simba Hello, this is the kind I wrote first but in coahcode's solution the stopped at "120"
0
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;
}
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;
}
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;
}
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
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