Advertisement

Random Pattern in C++ text mode

Started by February 08, 2000 05:14 PM
5 comments, last by Ray745 24 years, 7 months ago
how would i get a random pattern of stars * to appear on the screen in text mode i used a random number generator to generate numbers between one and 50 and thn i used the gotoxy() function in conio.h to randomly set the cursor position then print out a star but this is what i did gotoxy(num,num) num being the random number generated by the computer...the program would just skip this over and ignore the gotoxy functions i used the help and read it ignored it because it only tyakes numbers, is there any other way i can acheive this random pattern of stars on the screen in the text mode of C++ thanks If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...
If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...
I suppose you could randomly generate a number of stars per line (0-whatever) and then generate x positions for each of the stars you just picked a number for, for each line you want to cover in the y direction....


-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
What you''re doing sounds like it should work. Make sure that the numbers are within range of the x and y limits of the screen, and remember to call the randomize() function before using rand()... thats all I can suggest.

Hope that helped.
- DanielMy homepage
everything in my code is working except for the gotoxy part it will only take written numbers, like gotoxy(2,13) and i am giving it gotoxy(num,num) with num being the random number generated by the computer the compiler totally skips over the gotoxy(num,num) so i need either a new way or a way around this thanks

If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...
If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...
just out of curiosity...whose compiler are you using? that''s a pretty weird scenario.


aaron
-----------------------------
LeChuck! GRRRRRR.
----------------------------------------Look behind you! A three-headed monkey!
Ray..

Check what sort of value you are passing to goto(x, y).

It may require a byte (8 bit unsigned int), and you are likely to be using floats (32 bit signed) when generating or working with random numbers.

It''s worth checking the docs.
Advertisement
im using borlands 5.02 and no im not using a float i am using an int i really dont know why this is happening

If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...
If I only had a nickle for every problem I''ve had, I wouldn''t have anymore problems, but then I guess I wouldn''t have anymore nickles either...

This topic is closed to new replies.

Advertisement