
-----------------------------------
Fatalsh0ts
Sun Jun 14, 2009 2:45 pm

Need help with this program..
-----------------------------------
1. Write a program that continually asks a user for a number until they enter 0.  Output the lowest number that they entered.  
 this is what i have so far.

var numb, numb2 : real
put "Enter a number: " ..
get numb
for x : 1 .. 1000
    if numb > 0 then
        put "Enter a number: " ..
        get numb
    elsif numb = 0 then
        exit
    end if
end for

i dont know how ot output the lowest number

-----------------------------------
DtY
Sun Jun 14, 2009 3:00 pm

RE:Need help with this program..
-----------------------------------
You have to store the lowest number as you're going through. If they enter a number lower than the lowest number, that new number is the lowest.

And use loop instead of for.

-----------------------------------
BigBear
Sun Jun 14, 2009 3:00 pm

RE:Need help with this program..
-----------------------------------
You should use a conditional loop because a for loop exits after a certain amount of times in your code 1000 times.

But what if they enter 100 numbers and none of them are 0

You also need to store the lowest entered

-----------------------------------
Kharybdis
Sun Jun 14, 2009 3:19 pm

Re: Need help with this program..
-----------------------------------
Something like this maybe. This is done to find the largest integer entered..
var number : string
var largest : string
var flag := true
loop
    loop
        put "Please enter a number. 0 to exit!"
        put "user> " ..
        get number
        if flag then
            largest := number
        end if
        flag := false
        exit when strintok (number)
        put "That is invalid input!"
    end loop

    exit when strint (number) = 0
    if strint (number) > strint (largest) and strint (largest) not= 0 then
        largest := number
    end if
end loop
put "The largest number that you've entered is, ", largest, "."
