ECE 190 Midterm Exam 1 - Number Guessing Game, Exams of Biomedical Engineering

The instructions for a programming assignment in which students are required to write a number guessing game using binary search. The game involves the user picking a number between 0 and 100, and the program making educated guesses based on user feedback. The document also includes information on how to compile and submit the program.

Typology: Exams

2012/2013

Uploaded on 04/01/2013

nishaa
nishaa 🇮🇳

4.3

(13)

56 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE#190!Midterm(Exam(1!
Spring!2011!
Wednesday,)February)16,)2011)
In this assignment, you will need to write a program that guesses a number that the user picks. First, your program
should tell the user to pick a number between 0 and 100 by printing "Come up with a number
between 0 and 100." Then, your program will guess the value, and the user will enter either >, <, or =,
telling your program that your guess is too small, too big, or exactly right. You will use the binary search method
to guess a number, meaning that if you know the number is between a and b, you will guess (a+b)/2. Your
guesses must be integer, so if a+b is odd, please round down. You must use all the information the user provides
in each round. Continue to make guesses until the user enters =.
Sample run of your program when user guessed number 73 must look like this:
Come up with a number between 0 and 100.
I guess 50. >
I guess 75. <
I guess 62. >
I guess 68. >
I guess 71. >
I guess 73. =
Note that if you use scanf to take your user input, some of the characters scanned by scanf will be invalid
(\n and \r) as well as the user may inadvertently enter a wrong symbol. Your program needs to ignore such
input.
Also note that we have specified the problem so that there is only one correct guess sequence for any given
user number. Be sure your program follows that sequence.
Finally, note that your program may repeatedly guess the same value, but ONLY WHEN the user has lied about
the actual value, or picked a value outside of the range.
Name your program file exam1.c. You sh ou l d co m pi le y o ur c o de either using make or as follows:
gcc -g -Wall -Werror -ansi exam1.c -o test
Make sure your program compiles and works before your turn it in. We wil l not gr ad e a p rog ram t hat d oes no t
compile and you will lose points if the program compiles with warnings. You obviously will not receive any
points if your program does not do what it is supposed to do. Both functionality and coding style will be graded,
with most points given for functionality and some points given for style. No style grading will be done if the
program does not compile. Make sure that your output EXACTLY matches the specified structure and example,
including spacing and punctuation.
When you are finished, ensure the program compiles and call the proctor.

Partial preview of the text

Download ECE 190 Midterm Exam 1 - Number Guessing Game and more Exams Biomedical Engineering in PDF only on Docsity!

ECE 190 Midterm Exam 1

Spring 2011

Wednesday, February 16, 2011 In this assignment, you will need to write a program that guesses a number that the user picks. First, your program

should tell the user to pick a number between 0 and 100 by printing "Come up with a number

between 0 and 100." Then, your program will guess the value, and the user will enter either > , < , or = ,

telling your program that your guess is too small, too big, or exactly right. You will use the binary search method to guess a number, meaning that if you know the number is between a and b , you will guess ( a + b )/2. Your guesses must be integer, so if a + b is odd, please round down. You must use all the information the user provides

in each round. Continue to make guesses until the user enters =.

Sample run of your program when user guessed number 73 must look like this: Come up with a number between 0 and 100. I guess 50. > I guess 75. < I guess 62. > I guess 68. > I guess 71. > I guess 73. =

Note that if you use scanf to take your user input, some of the characters scanned by scanf will be invalid

(\n and \r) as well as the user may inadvertently enter a wrong symbol. Your program needs to ignore such

input. Also note that we have specified the problem so that there is only one correct guess sequence for any given user number. Be sure your program follows that sequence. Finally, note that your program may repeatedly guess the same value, but ONLY WHEN the user has lied about the actual value, or picked a value outside of the range.

Name your program file exam1.c. You should compile your code either using make or as follows:

gcc - g - Wall - Werror - ansi exam1.c - o test

Make sure your program compiles and works before your turn it in. We will not grade a program that does not compile and you will lose points if the program compiles with warnings. You obviously will not receive any points if your program does not do what it is supposed to do. Both functionality and coding style will be graded, with most points given for functionality and some points given for style. No style grading will be done if the program does not compile. Make sure that your output EXACTLY matches the specified structure and example, including spacing and punctuation. When you are finished, ensure the program compiles and call the proctor.