Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bioagentX

A for Loop

This topic is 5600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is the code for my for loop. For some reason, it doesn''t display the correct amount of numberse

/*Chapter 4 Excercise 24 Program
By Brendan Harnett (C) Brendan Harnett All Rights Reserved*/


#include

int main()
{





for(int x=1; x<=400; x++)//displays numbers from 1000 to 0
{


 cout<

Share this post


Link to post
Share on other sites
Advertisement
Well ... you might want to make it output something



i.e.
cout <

to
cout << x; in your code which you copied - unless you have an extreem case of typos ( //displays numbers from 1000 to 0 ) <--



~ Take care.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
works for me, using .net 2k3


for(int x = 0; x <= 400; x++)
cout << " " << x;


as long as you''ve #include <iostream> you shouldn''t be having problems. what version of msvc are you using?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
crud, that should have been
for(x = 1; x <= 400...

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
crud, that should have been
for(x = 1; x <= 400...




if it should''ve been "for(x=1; x <= 400;..." be sure you have
defined x before the for loop otherwise you''ll get an error about x being undefined.

Share this post


Link to post
Share on other sites
Ok, here''s the actual real code:


/*Chapter 4 Excercise 24 Program
By Brendan Harnett (C) Brendan Harnett All Rights Reserved*/


#include

int main()
{





for(int x=0; x<=400; x++)//displays numbers from 0 to 400
{


cout<
}

int stayopen;
cin>>stayopen;

return 0;

}


For some reason, it only displays the numbers from 102 to 400. I don''t know why, it could have something to do with XP''s windows size. Because on my older computer the program works, however, on my new one with windows XP, it''s not generating the necessary numbers.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Its probably just the your window buffer isn''t large enough and the numbers 0-101 are not being helf. Pipe the output to a text file and open that by doing programname.exe | output.txt from the command prompt.

Share this post


Link to post
Share on other sites
... You mean to say that the only problem is that the first numbers are not present in the console window''s buffer? Sheesh. Just try exchanging "cout << x << endl;" for "cout << x << " " << flush;" or something similar (I know it''s slow and it''s not how I''d do it, but it''s the simplest way) and see if it works. By the way, in the console window''s settings you should be able to increase the default buffer size ...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!