+ 1

17.2 C++ Help

So Im not sure what I am doing wrong but any time I input my code it just says there is no output. I don't know if I am just missing something silly or if it's not working. Getting frustrated and discouraged but I can't figure out what I'm doing wrong. #include <iostream> using namespace std; int main() { int d = 0; //your code goes here for(d = 0; d == 200; d +=40){ cout << d << endl; } return 0; } Any help would be greatly appreciated as I am completely lost as to what I did wrong. Thank you in advanced!

31st Aug 2021, 12:25 PM
Wade
Wade - avatar
3 Answers
+ 3
In your code When it runs for the first time it checks if d==200, which is false, as d is 0, so it terminates your loop without going inside and as a result does not print anything. Just change you conditional value to d<=200 then it will print values having incrementation of 40 upto 200.
31st Aug 2021, 12:46 PM
HK Lite
HK Lite - avatar
+ 1
Distance = speed * time int speed = 40; for(int hour=1; hour<=5; hour++){ cout<< speed*hour <<endl; }
31st Aug 2021, 12:37 PM
SAN
SAN - avatar
0
Ahhhh okay, I'll try that, thank you!
31st Aug 2021, 12:41 PM
Wade
Wade - avatar