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

Username:   Password: 
 RegisterRegister   
 Loop help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
KONjbnj




PostPosted: Tue Apr 12, 2005 8:11 am   Post subject: Loop help

hello,
i have a problem how do u make it so that when you loop 2 variables they do not have the same value ie.

a program which will ask the user to enter two integer numbers. You want to swap the numbers so that larger of the two numbers is stored in the variable, Large, and the smaller of the two is stored in the variable, Small. and then loop so it asks the user to eneter 2 more.

whenever i do this it keeps the value of the numbers which i used the second time can anyone help??/
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: Tue Apr 12, 2005 8:24 am   Post subject: (No subject)

here ya go, what it does is checks to see if its larger then the largest variable, look at it to see qwhat i mean

code:

var a, b, largest : int := 0

loop
    put "Enter data: " ..
    get a
    put "Enter data: " ..
    get b

    if largest > a and largest > b then

    elsif a > b then
        largest := a
    elsif b > a then
        largest := b
    end if
    put "The largest number entered so far was ", largest


end loop
Martin




PostPosted: Tue Apr 12, 2005 8:24 am   Post subject: (No subject)

KONjbnj, I don't have a clue what you're talking about.
StarGateSG-1




PostPosted: Tue Apr 12, 2005 11:06 am   Post subject: (No subject)

I think I understand it after reading for 15 minutes, but this seems like a school question, so I won't give you the code.

but the idea you want is to have a tempvar
code:

variables
tempa
tempb
largest
smallest

Body
loop
Ask for first number
Move it to temp
Ask for second number
Move it to temp
check for largest with first number
move to largest
check for largest with second number
move to largest check
check for smallest number with first number
move to smallest
check for smallest number with second number
The largest number so far was Bah
end loop
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: