Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-02-2007, 05:17 PM   #1
Member (9 bit)
 
Sam-U-Rai's Avatar
 
Join Date: Sep 2006
Location: NYC
Posts: 272
Trying to do Matrixy Text in C++

While we were doing loop demos in class (HS C++ Half-year course), me and my friend found that if you set the loop number (middle section) to more than a couple thousand, it'll keep running text over the screen up and down.


Well, I was just trying to do this at home and Idk if I did it right. It'll just print it once. The main thing I'm getting at is that I want a constant flow of numbers and letters just for kicks to look cool.


Here's the code I just made in Visual C++:
I think I got some of the Loop code wrong. Help me out if you can guys .

#include(Iostream Library in C++, Forum won't show)
#include(Iomanip.h Library in C++, Forums won't show)

int main (void)
{
int x;

{
for (x=1 ; x>=2000000; x+=1);

cout<<"1 2 3 4 5 "<<(endl; I CAN"T DO THIS ON FORUMS CAUSE IT JUST SKIPS LINE -->BASICALLY ENDL
}




return 0;


}

Last edited by Sam-U-Rai; 03-02-2007 at 05:20 PM.
Sam-U-Rai is offline   Reply With Quote
Old 03-02-2007, 06:57 PM   #2
Moderator
Staff
Premium Member
 
Join Date: Aug 2003
Location: Richmond, VA
Posts: 7,835
The for loop should have its own scope - you have the starting bracket before the for statement. In short, it should be something like:
PHP Code:
for (x=1x>=2000000x++)
{    
cout << 12345 << endl;

Try cleaning up the code a bit and see what happens.

kram
__________________
"For today, goodbye. For tomorrow, good luck. And forever, Go Blue!"
University of Michigan President Mary Sue Coleman
kram 2.0 is offline   Reply With Quote
Old 03-02-2007, 11:58 PM   #3
FLG
Member (11 bit)
 
FLG's Avatar
 
Join Date: May 2003
Location: Brooklyn, NY
Posts: 1,798
Send a message via AIM to FLG
I believe this is what your trying to do. I made 2 loops. Just pick one. Though the "for" loop will eventually end, the "while (true)" will continue on until you close the window. btw, i commented out the loops so just remove the "//" when you write it. And just a note, you should not put "void" in the parameters for "main", and try not to use any includes if you dont need them...iomanip for example. Also, you can scrap the "return 0;" and finally, when you using a "for" loop it makes for cleaner code to make and initialize the variable in the parameters of the loop.

Edit: one more thing (sorry if im a little to much, just want to try to help with your code.) you dont need the "{" blocks in a loop unless its more then one line (though its fine if you do have them), and scrap the ";" at the end of the "for" loop. Finally, you have one the blocks in the wrong place. You would need one to open main and one to close, if you used it on the "for" loop you would need one right after the ")" on the "for" and one at the end of the loop.
Attached Images
File Type: jpg loop.JPG (11.3 KB, 24 views)

Last edited by FLG; 03-03-2007 at 12:08 AM.
FLG is offline   Reply With Quote
Old 03-03-2007, 05:38 AM   #4
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
Quote:
Originally Posted by Sam-U-Rai
While we were doing loop demos in class (HS C++ Half-year course), me and my friend found that if you set the loop number (middle section) to more than a couple thousand, it'll keep running text over the screen up and down.


Well, I was just trying to do this at home and Idk if I did it right. It'll just print it once. The main thing I'm getting at is that I want a constant flow of numbers and letters just for kicks to look cool.


Here's the code I just made in Visual C++:
I think I got some of the Loop code wrong. Help me out if you can guys .

#include(Iostream Library in C++, Forum won't show)
#include(Iomanip.h Library in C++, Forums won't show)

int main (void)
{
int x;

{
for (x=1 ; x>=2000000; x+=1);

cout<<"1 2 3 4 5 "<<(endl; I CAN"T DO THIS ON FORUMS CAUSE IT JUST SKIPS LINE -->BASICALLY ENDL
}




return 0;


}

errrr...........

I think u got the condition wrong in the "for loop" with
x>=20000000 <------loop stops at printing one line because condition is met!

should be
x<=20000000 instead. <-----will print 20000000 lines before ending.

however, it would look better if the program runs infintely until a input is read, much like FLG's infinte while loop, one post above this post.
__________________
words to live by:
others don't know, I know.
others know, I know more.
others know more, I excel.
one shouldnt read this far; above, is meant as an encouragement, translated from a Chinese Proverb.
"He who angers you conquers you." : Elizabeth Kenny

Last edited by alfie2; 03-03-2007 at 05:44 AM.
alfie2 is offline   Reply With Quote
Old 03-03-2007, 08:39 AM   #5
Member (9 bit)
 
Sam-U-Rai's Avatar
 
Join Date: Sep 2006
Location: NYC
Posts: 272
Quote:
Originally Posted by alfie2
errrr...........

I think u got the condition wrong in the "for loop" with
x>=20000000 <------loop stops at printing one line because condition is met!

should be
x<=20000000 instead. <-----will print 20000000 lines before ending.

however, it would look better if the program runs infintely until a input is read, much like FLG's infinte while loop, one post above this post.

Thanks for the help! I changed it and now its doing it completely. Hell yeah, thank you guys.
Sam-U-Rai is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox text size increase affects menu bar and ads Londoner Internet, Web Applications, & The Cloud 4 02-19-2007 02:28 PM
Text Message EFG Tech Windows Tips, Tricks, and Tweaks 2 06-05-2006 06:38 AM
Focus or tracking error nokiafan05 Computer Hardware 0 02-15-2006 10:19 PM
Burrner randomly shooting duds - Please Help! Zac3010 Computer Hardware 18 04-20-2004 09:40 PM
I can't BURN>>>> john ranger Windows Legacy Support (XP and earlier) 24 05-15-2003 01:51 PM


All times are GMT -5. The time now is 07:26 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2