Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 12-03-2006, 09:10 PM   #1 (permalink)
 
Newb Techie

Join Date: Oct 2006

Posts: 11

skullker

Send a message via AIM to skullker
Default I need help with java loops

i am making a program where they try to guess a number between 1 and 100 and i have it all but i cant figure out how to make a loop where if the number they enter is greater than answer than it tells them "your too high" and if the number they enter is too low it tells them "your to low" then they try again it repeats until they get it

so how would i do the loop
skullker is offline  
Old 12-04-2006, 12:50 AM   #2 (permalink)
Apokalipse's Avatar
 

Join Date: Jun 2003

Location: Melbourne, Australia

Posts: 13,714

Apokalipse has a spectacular aura aboutApokalipse has a spectacular aura about

Default

I haven't done a whole lot of programming (I've only used my TI-84, and a little bit of C), but I think this should do it:
make the guessed number, and the randomly picked number to be different variables (for example X for guessed number, Y for randomly picked number)

then do something like this:

If X>Y
Print "Too high"
If X<Y
Print "Too Low"
__________________

1 + 1 = 3 if you define 3 as a result of 1 + 1
Apokalipse is offline  
Old 12-04-2006, 01:08 AM   #3 (permalink)
 
Newb Techie

Join Date: Oct 2006

Posts: 34

jeff00z28

Default

first you'd have to define the variable(s), and then input the guessing number as a variable, then do the if statement.
jeff00z28 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On