
-----------------------------------
AK.E
Fri Jan 19, 2007 2:10 pm

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:

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."  


-----------------------------------
Clayton
Fri Jan 19, 2007 4:02 pm

Re: Negatives
-----------------------------------
use natural numbers instead of integers


var my_nat : nat := 5


-----------------------------------
Cervantes
Fri Jan 19, 2007 5:03 pm

Re: Negatives
-----------------------------------
There are strnat and strnatok functions, yes? Using those would solve your problem.
