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

Username:   Password: 
 RegisterRegister   
 Negatives
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AK.E




PostPosted: Fri Jan 19, 2007 2:10 pm   Post subject: Negatives

I have a program in which I want to get a number but prevent them from entering negatives. I know I can simply use if number < 0 then... but that only works for the first time. Let's say someone enters -5.. it won't except it.. but when they enter 100 then -5 it will because the number will be 95 which is above 0.

Here's my code:
Turing:

var numberOfBars : string
var numberOfBarsInt : int
var barX : int := 0

get numberOfBars                                 


        if strintok (numberOfBars) then       

            numberOfBarsInt := strint (numberOfBars) + barX     

            put numberOfBarsInt                             


        else

            put " "

            put "Please insert a valid integer." 
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Fri Jan 19, 2007 4:02 pm   Post subject: Re: Negatives

use natural numbers instead of integers

Turing:

var my_nat : nat := 5
Cervantes




PostPosted: Fri Jan 19, 2007 5:03 pm   Post subject: Re: Negatives

There are strnat and strnatok functions, yes? Using those would solve your problem.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: