So I have to write a program that guesses a number chosen by a user. My program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. But the problem is I have to guess the user’s number in four questions or less. What should I ask?
Guessing Game Question
Page 1 of 13 Replies - 1088 Views - Last Post: 24 January 2014 - 12:28 AM
Replies To: Guessing Game Question
#2
Re: Guessing Game Question
Posted 23 January 2014 - 09:20 PM
Hint- look at binary search.
#3
Re: Guessing Game Question
Posted 23 January 2014 - 10:08 PM
Okay so, this is my pseudo code so far but.. what should i do with 9,10 and 6,7?
How come I have to ask 6 or more questions?
Variable declarations
If user picks a number from 1 to 10
Do 10 divided by 2 before asking a yes/no question which is 5
Ask “yes” or “no” questions
If asked “is it less than or equal to 4?”
If user says “yes”
Generate 1,2, 3, and 4
Else
Generate 5,6,7,8,9, and 10
If user said “yes” earlier
4 plus 2 divided by 2 which 3
If asked “is it greater than or equal to 3?”
If user says “yes”
Generate 3, and 4
Else
Generate 1, and 2
If user said “no” earlier
5 plus 10 divided by 2 which is 7.5
If asked “is it greater than or equal to 7.5?”
If user says “yes”
Generate 8,9 and 10
Else
Generate 5,6, and 7
If the number is greater than equal to 3 which is 3, and 4
3 plus 4 divided by 2 which is 2.5
If asked “is it less than 2.5?”
If user says “yes”
Your number is 3
Else
Your number is 4
If number is not greater than or equal to 3
1 plus 2 divided by 2 which is 1.5
if asked “is it less than 1.5?”
if user says “yes”
Your number is 1
Else
Your number is 2
If the number is greater than 7.5
8 plus 10 divided by 2 which is 9
if asked “is it less than 9?”
if users says “yes”
Your number is 8
Else
Your number is 9 or 10
If the number is less than 7.5
5 plus 6 divided by 2 which is 5.5
If asked “is it less than 5.5?”
If user says “yes”
Your number is 5
Else
Your number is 6 or 7
How come I have to ask 6 or more questions?
Variable declarations
If user picks a number from 1 to 10
Do 10 divided by 2 before asking a yes/no question which is 5
Ask “yes” or “no” questions
If asked “is it less than or equal to 4?”
If user says “yes”
Generate 1,2, 3, and 4
Else
Generate 5,6,7,8,9, and 10
If user said “yes” earlier
4 plus 2 divided by 2 which 3
If asked “is it greater than or equal to 3?”
If user says “yes”
Generate 3, and 4
Else
Generate 1, and 2
If user said “no” earlier
5 plus 10 divided by 2 which is 7.5
If asked “is it greater than or equal to 7.5?”
If user says “yes”
Generate 8,9 and 10
Else
Generate 5,6, and 7
If the number is greater than equal to 3 which is 3, and 4
3 plus 4 divided by 2 which is 2.5
If asked “is it less than 2.5?”
If user says “yes”
Your number is 3
Else
Your number is 4
If number is not greater than or equal to 3
1 plus 2 divided by 2 which is 1.5
if asked “is it less than 1.5?”
if user says “yes”
Your number is 1
Else
Your number is 2
If the number is greater than 7.5
8 plus 10 divided by 2 which is 9
if asked “is it less than 9?”
if users says “yes”
Your number is 8
Else
Your number is 9 or 10
If the number is less than 7.5
5 plus 6 divided by 2 which is 5.5
If asked “is it less than 5.5?”
If user says “yes”
Your number is 5
Else
Your number is 6 or 7
This post has been edited by edwardpark: 23 January 2014 - 10:15 PM
#4
Re: Guessing Game Question
Posted 24 January 2014 - 12:28 AM
Edited this is what i did so far? so far so good?
Variable declarations
If user picks a number from 1 to 10
Do 10 divided by 2 before asking a yes/no question which is 5
Ask “yes” or “no” questions
The program will automatically do 5 plus 1 divided by 2 which is 3
If asked “is your number equal to 3?”
If user says “yes”
Your number is 3
Else if asked "is 3 too high?"
Your number is 1 or 2
Else
Your number is 3 or 4
The program will automatically do 6 plus 10 divided by 2 which is 8
If asked "is your number equal to 8?"
if user says "yes"
Your number is 8
Else if asked "is 8 too low?"
Your number is 6 or 7
Else
Your number is 8 or 9 or 10
This post has been edited by edwardpark: 24 January 2014 - 12:38 AM
Page 1 of 1

New Topic/Question
Reply


MultiQuote





|