5

A Number-Guessing Game

 2 years ago
source link: http://programmingbydoing.com/a/a-number-guessing-game.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
A Number-Guessing Game
  • Author: Graham Mitchell
  • Filename: NumberGuess.java

A Number-Guessing Game

Modify your incredibly stupid number-guessing game to actually pick a random number from 1 to 10 and have the user try to guess that. Tell them if they get it right or wrong, and if they get it wrong, show them what the random number was.

They will still only get one try.

I'm thinking of a number from 1 to 10.
Your guess: 3

Sorry, but I was really thinking of 4.
I'm thinking of a number from 1 to 10.
Your guess: 4

Sorry, but I was really thinking of 7.
I'm thinking of a number from 1 to 10.
Your guess: 2

That's right!  My secret number was 2!

©2013 Graham Mitchell

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
Creative Commons License


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK