Wednesday, January 25, 2012

Lab 6: Hot or Cold

For this lab you will implement a simple game where your program 'thinks' of a number between 0 and 1000 and the user has to guess it. The user will keep trying to guess until he finally gets it right, at which point your program will end. Below is a sample run of the program:
I am thinking of a number between 0 and 1000. Try to guess it.
Your guess:500
You are Cold
Your guess:600
You are Cold
Your guess:700
You are Hot
Your guess:800
Warm
Your guess:650
Warm
Your guess:720
Warm
Your guess:700
You are Hot
Your guess:710
You are Hot
Your guess:720
Warm
Your guess:690
Warm
Your guess:715
Warm
Your guess:705
You got it! Congratulations!
Game Over

As you can see, your program will tell the user how far his guess is from the correct answer using hot-or-cold words, the closer he is the hotter he is. Specifically, if the user is
  • a distance of less than 5 from the correct answer then he is Burning
  • less than 10 then he is Hot
  • less than 100 and he is Warm
  • less than 300 he is Cold
  • otherwise he is Freezing

Also, remember that the program must end after the user guesses correctly.

Hint: To generate a random number use Math.random(), then multiply that by 1000.

Hint: To get the absolute value of a number (the positive of it), use Math.abs().

As always, you will turn in your finished lab at the dropbox.cse.sc.edu.

No comments: