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

Username:   Password: 
 RegisterRegister   
 help: inputting fixed # of characters for integers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jas




PostPosted: Sun Mar 20, 2005 10:19 pm   Post subject: help: inputting fixed # of characters for integers

I am doing a big program in turing for school and i need help. How do u make a program so the user inputs a fixed number of characters for integers. For example, you can do this for a string by:

var code : string (9)
var familyCode : string (2)
var productCode : string (4)
var supplierCode : string (2)
var locationCode : string (1)

but if u do this...

var code : int (9)
var familyCode : int (2)
var productCode : int (4)
var supplierCode : int (2)
var locationCode : int (1)

the program crashes.

Also, how do u search for a pattern in an integer. If you declard the code variables as integers, and u try to do the following, the program crashes:

familyCode := code (1 .. 2)
productCode := code (3 .. 6)
supplierCode := code (7 .. 8)
locationCode := code (9 .. *)

How do u search for a pattern if it is an integer?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Mar 20, 2005 10:36 pm   Post subject: (No subject)

For the first question:
code:

var num := ""
var input : string (1)
var numOfDigits := 7
loop
    getch (input)
    exit when input = "\n" %exit when enter is pressed
    if strintok (num + input) and length (num + input) <= numOfDigits then
        num += input
    end if
    locate (1, 1)
    put num
end loop

You could also expand that so that you can use the backspace key. Not too difficult.

Second question:
use index. index searches a string though, so you first have to convert the int to a string.
code:

if index (intstr (variable), pattern) then
...
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  [ 2 Posts ]
Jump to:   


Style:  
Search: