Re: Random Password

new topic     » goto parent     » topic index » view thread      » older message » newer message

Alex Blanchette wrote:
> 
> 
> I'm trying to write a simple DOS program that makes a random 6 number password
> when you press enter, but for somereason it won't start when I press enter,
> it just starts on its own and doesn't stop, is there a way I can fix this?
> How do I get it to print six random numbers on one line if I can only use
> one %d command in a puts() command?
> 
> (I just started programming about 4 days ago)

Hello Alex:

First of all, to make Euphoria wait until a key is pressed, you need 
the wait_key() function, perhaps as follows:
include get.e

integer key, password

key = wait_key() -- program will pause here until you hit a key


Then, below that, you put the code to generate a random number
password = rand(999999) -- up to 6 digits


Now, that random number may sometimes have 6 digits, but most often
it will be shorter, as 999999 is just the maximum value, zero will be 
the minimum. So you want to always display 6 digits regardless of the 
value:
printf(1,"%06d",password)


You may also want to add some prompts so users of your program will 
know what to do, so the complete program might look like this:
include get.e

integer key, password

puts(1,"Press the enter key:")
key = wait_key()

password = rand(999999)
printf(1,"\nYour password is: %06d",password)


new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu