Computer Science Canada

ok i have rand int problems here :D

Author:  xmdxtreme [ Sat May 15, 2004 9:46 pm ]
Post subject:  ok i have rand int problems here :D

See i want my program to creat random accounts till 4 digits excluding MG- at the begining like i want it to make account like:
MG-3445
MG-3425
can somoene help me i tried real hard i cant get it to work like this.
then just to let you know later on when the user type the account number it will look at the fisrt 3 characters MG- then it will know it has to go to manager account. but if it SC- at the begining then it will take them to Savings and chequings account. its sound a bit complicated Rolling Eyes lol

Author:  xmdxtreme [ Sat May 15, 2004 10:01 pm ]
Post subject: 

please help Embarassed i got 1 more day for my first report.

Author:  jonos [ Sat May 15, 2004 10:13 pm ]
Post subject: 

Well you should just put the randomly generated accounts in an array and check the array against what they entered. Post some code so we know what you mean.

Author:  SuperGenius [ Sat May 15, 2004 10:13 pm ]
Post subject: 

ok. in a loop create a random integer and pass the value to a string which already includes the prefix you want.
accountnum will of course be a string var, and prefix would also be one, with a value like "MG" You could also create the other types of accounts by changing the prefix that is used

code:

accountnum (a) := prefix + "-" + intstr (randomnumber)

Author:  xmdxtreme [ Sun May 16, 2004 7:04 am ]
Post subject: 

I dont get it should i use a for loop or loop.
BTW can you explain your code sry.

Author:  we64 [ Sun May 16, 2004 8:03 am ]
Post subject: 

I think this is what he meant:
code:

var accountnum : array 1 .. 10 of string
var prefix : string := "MG"
var randomnumber : int
for a : 1 .. 10
    randint (randomnumber, 1000, 9999)
    accountnum (a) := prefix + "-" + intstr (randomnumber)
    put accountnum (a)
end for

Author:  xmdxtreme [ Sun May 16, 2004 8:10 am ]
Post subject: 

thank you! +10 bits

Author:  Martin [ Sun May 16, 2004 1:06 pm ]
Post subject: 

Just an FYI, Rand.Int(low, high) is easier to use, because it is a function instead of a procedure. This way, your code would look like this (much shorter)

code:
var accountnum : array 1 .. 10 of string
var prefix : string := "MG"
for a : 1 .. 10
    accountnum (a) := prefix + "-" + intstr (Rand.Int (1000,9999))
    put accountnum (a)
end for

Author:  SuperGenius [ Sun May 16, 2004 2:23 pm ]
Post subject: 

Darkness wrote:


code:
var accountnum : array 1 .. 10 of string
var prefix : string := "MG"
for a : 1 .. 10
    accountnum (a) := prefix + "-" + intstr (Rand.Int (1000,9999))
    put accountnum (a)
end for


this is indeed what I meant, I was just hoping that you could come up with that yourself though.


: