+ 3
c++ 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. My attempt is in the comments
9 ответов
+ 2
It count up. hour++ is hours = hours + 1
We need to increment in the loop
+ 2
It get incremented by one on each iteration – just like the k in your attempt
+ 1
Lisa but wouldnt that make hours = 2?
0
#include <iostream>
using namespace std;
int main()
{
int distance = 0;
for (int k = 40; k < 200; k+=40){
cout << "k" << endl;
return 0;
}
0
I don't understand what you intend with the for loop. Can you explain, please?
According to the task description, you should only do one calculation and output.
0
Lisa It should output 40 80 120 160 200
0
Ah, okay, sorry! Misunderstood the question!
0
Martin Taylor what is the hours++ for?
0
Can helb me