#pragma hdrstop
#include <condefs.h>
#include <conio.h>
#include <iostream.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
for (int i=200;i>300;i++)
{
cout << "# " << i << "." << endl;
}
getch();
return 0;
}
All I see when I compile and run this program is a blank screen, waiting for input from the keyboard (getch()). Any help would be greatly appreciated. Also, no errors or warnings are brought up by the compiler.
What is wrong with this simple FOR loop?
I''m having a rough time here. As you can see, I am an extreme newbie to C++ (although done some Basic and Pascal before), and the sybtax is a little different I''ve noticed. Even so, I don''t see what''s wrong with this code:
LOL - replace the > with <.
---------------
I finally got it all together...
...and then forgot where I put it.
---------------
I finally got it all together...
...and then forgot where I put it.
February 13, 2002 05:04 PM
I think this line is your problem
it should say
for (int i=200;i>300;i++)
it should say
for (int i=200;i<300;i++)
your for loop should look like this:
for(int i=200; i < 300; i++)
then the rest of your code. Think of for statements as kind of a while loop that does the initialization, control, and iteration in one easy statement,even though when you get into the particulars of implementation the two..blah nevermind. Just think of the control statement in the for loop (the i < 300 part) as meaning the same as while(i < 300).
for(int i=200; i < 300; i++)
then the rest of your code. Think of for statements as kind of a while loop that does the initialization, control, and iteration in one easy statement,even though when you get into the particulars of implementation the two..blah nevermind. Just think of the control statement in the for loop (the i < 300 part) as meaning the same as while(i < 300).
all he needs to know is to remember that the > points to the smaller number.
Doh, I figured it would be something stupid. Thank you everyone, and eotvos your explanation helped clear it up. Thanks!
(Oh BTW: How do you do that cool thing where the code shows up all nice and pretty? I just used
(Oh BTW: How do you do that cool thing where the code shows up all nice and pretty? I just used
.. )
Heh, it''s not that, it''s just that for some reason I was thinking with the logic "Repeat until i is greater than 300" instead of "While i is less than 300 do this".
February 13, 2002 05:20 PM
For the code stuff look here...
<a HREF="http://www.gamedev.net/community/forums/faq.asp">Forum FAQ</a>
<a HREF="http://www.gamedev.net/community/forums/faq.asp">Forum FAQ</a>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement