Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ok i have rand int problems here :D
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xmdxtreme




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
xmdxtreme




PostPosted: Sat May 15, 2004 10:01 pm   Post subject: (No subject)

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




PostPosted: Sat May 15, 2004 10:13 pm   Post subject: (No 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.
SuperGenius




PostPosted: Sat May 15, 2004 10:13 pm   Post subject: (No 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)
xmdxtreme




PostPosted: Sun May 16, 2004 7:04 am   Post subject: (No subject)

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




PostPosted: Sun May 16, 2004 8:03 am   Post subject: (No 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
xmdxtreme




PostPosted: Sun May 16, 2004 8:10 am   Post subject: (No subject)

thank you! +10 bits
Martin




PostPosted: Sun May 16, 2004 1:06 pm   Post subject: (No 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
SuperGenius




PostPosted: Sun May 16, 2004 2:23 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: