Bon Voyage!
Greetings everyone. I'm new to coding. This question gave me issues so I thought I would share my solution. Once I solved it successfully, I googled the question to see what others came up with. Their solutions were different. Everyone solved it in a way that assumes you know the boat traveled 200 km. I know it is simple math, but I wanted a way for this to work with any set of numbers without doing mental math lol. If any expert sees this, feel free to chime in! 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 kilometers the ship has traveled by each hour. #include <iostream> using namespace std; int main() { int distance = 0; // inital distance, will be updated as we go int time = 5; // how many hours int speed = 40; // km per hour int sum ; // too distance based on hours at set speed sum = speed * time; for (distance = 40; distance <= sum; distance += 40) { /* if traveling a 40 km per hour, when the distance is less than or equal to the total distance; increment the km per hour by 40 */ cout << distance << endl; // print the distance traveled each km on a separate line } return 0; } https://code.sololearn.com/ca21a2183A10/#cpp