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

Username:   Password: 
 RegisterRegister   
 Need help with this program..
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Fatalsh0ts




PostPosted: Sun Jun 14, 2009 2:45 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Sun Jun 14, 2009 3:00 pm   Post subject: 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




PostPosted: Sun Jun 14, 2009 3:00 pm   Post subject: 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




PostPosted: Sun Jun 14, 2009 3:19 pm   Post subject: Re: Need help with this program..

Something like this maybe. This is done to find the largest integer entered..
Turing:
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, "."
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  [ 4 Posts ]
Jump to:   


Style:  
Search: