+ 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!
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.
+ 1
Distance = speed * time
int speed = 40;
for(int hour=1; hour<=5; hour++){
cout<< speed*hour <<endl;
}
0
Ahhhh okay, I'll try that, thank you!