Data Journey

International Studies Grad. racing for AI Engineer

Download as .zip Download as .tar.gz View on GitHub
9 January 2021

Travel Distance

by mervyn

For Loop

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;
    //your code goes here
    for(int hour =1; hour <=5; hour++){

distance = hour*40;
cout<<distance<<endl;

}
    return 0;
}
tags:

Comments

Post comment
Loading...

Share this: