Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Higher-Lower Guessing Game Assignment for ECE 131 - Programming Fundamentals, Lecture notes of Advanced Computer Programming

Instructions and requirements for completing assignment 3 in the ece 131 - programming fundamentals course. The assignment involves writing a higher-lower guessing game program in c language, using terminal text input and output. The user tries to guess a randomly generated number within a given range, and receives feedback on whether their guess is too high or too low. The game continues until the user runs out of guesses or guesses the number correctly.

What you will learn

  • What are the feature requirements for the Higher-Lower Guessing Game program?
  • What does the Higher-Lower Guessing Game involve?
  • What is the purpose of Assignment 3 in the ECE 131 - Programming Fundamentals course?

Typology: Lecture notes

2021/2022

Uploaded on 09/12/2022

courtneyxxx
courtneyxxx 🇺🇸

4.5

(14)

253 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Code Assignment 3
Functions & Libraries
ECE 131 – Programming Fundamentals
Instructor: M. Wolverton
Items Due
hlgame.h hlgame.c main.c
Instructions
Complete the coding directive in your C language IDE of choice (Eclipse, NetBeans) or by command line compiling. Once you have
verified that the program works as intended, login to the file server at cec-code-lab.aps.edu and create a folder with the assignment
name (e.g. Code 3). Locate all .c and .h source files written by you (e.g. hlgame.h, hlgame.c, main.c) and upload them to into the
assignment folder. Code will be downloaded and archived for grading on the assignment due date.
Higher-Lower Guessing Game
Write a program that uses terminal text input and output to create a game where the computer generates a random number and the
user tries to guess it. The as the user guesses incorrectly, they should be told whether their guess is too high or too low. If the user
passes a certain number of guesses they lose, and if they guess the number in fewer tries, they win.
Feature Requirements
- Print program title or welcome message identifying the program and what it is.
- Before each entry, make the user aware of the number of guesses they have remaining and the valid guess range.
- Invalid entries should not consume a turn and the game should allow the user to attempt to guess again.
- Print a message announcing the user has lost if they run out of guesses and print target value - the program should end.
- If the user wins, announce that they have won somehow and end the program.
- [optional] Instead of ending the program at a win or loss, ask if they want to play again.
- [optional] Keep score of the player’s wins and losses for the session.
- [optional] Create three difficulty settings that expand the guess range and reduce the number of guesses at higher difficulties.
Code Structure
- Use no global variables anywhere in this project.
- Create a library consisting of a source file (hlgame.c) and a header file (hlgame.h). Include hlgame.h in your main source
code file for the project, main.c .
- Use each library function defined in your hlgame library at least once for its intended purpose.
- Prototype the following functions in hlgame.h, with full implementation in hlgame.c .
int checkGuess(int guess, int target)
Description: checkGuess Returns -1 if guess is less than target, 1 if guess is greater than actual, 0 if equal
void printEntryPrompt(int min, int max)
Description: printEntryPrompt prompts the user to enter a value in the range of min (inclusive) and max (exclusive)
with printf().
void printNumGuesses(int num)
Description: printNumGuesses tells the user how many guesses are remaining with printf().
int takeEntry(int min, int max)
Description: returns the user’s input. Uses scanf() and then uses getchar() to discard all characters until a line
return is found. Valid entries are in the range of min (inclusive) and max (exclusive). If an invalid entry is detected, the
function prints an error message and attempts to take entry again.
int makeRandNum(int min, int max)
Description: makeRandNum Returns a random int value in the range of min (inclusive) and max (exclusive) using rand.
Also Seeds the random number using srand and time(0) before generating the value.
pf2

Partial preview of the text

Download Higher-Lower Guessing Game Assignment for ECE 131 - Programming Fundamentals and more Lecture notes Advanced Computer Programming in PDF only on Docsity!

Code Assignment 3

Functions & Libraries

ECE 131 – Programming Fundamentals

Instructor: M. Wolverton

Items Due

  • hlgame.hhlgame.cmain.c

Instructions

Complete the coding directive in your C language IDE of choice (Eclipse, NetBeans) or by command line compiling. Once you have verified that the program works as intended, login to the file server at cec-code-lab.aps.edu and create a folder with the assignment name (e.g. Code 3). Locate all .c and .h source files written by you (e.g. hlgame.h, hlgame.c, main.c) and upload them to into the assignment folder. Code will be downloaded and archived for grading on the assignment due date.

Higher-Lower Guessing Game

Write a program that uses terminal text input and output to create a game where the computer generates a random number and the user tries to guess it. The as the user guesses incorrectly, they should be told whether their guess is too high or too low. If the user passes a certain number of guesses they lose, and if they guess the number in fewer tries, they win. Feature Requirements

  • Print program title or welcome message identifying the program and what it is.
  • Before each entry, make the user aware of the number of guesses they have remaining and the valid guess range.
  • Invalid entries should not consume a turn and the game should allow the user to attempt to guess again.
  • Print a message announcing the user has lost if they run out of guesses and print target value - the program should end.
  • If the user wins, announce that they have won somehow and end the program.
  • [optional] Instead of ending the program at a win or loss, ask if they want to play again.
  • [optional] Keep score of the player’s wins and losses for the session.
  • [optional] Create three difficulty settings that expand the guess range and reduce the number of guesses at higher difficulties. Code Structure
  • Use no global variables anywhere in this project.
  • Create a library consisting of a source file (hlgame.c) and a header file (hlgame.h). Include hlgame.h in your main source code file for the project, main.c.
  • Use each library function defined in your hlgame library at least once for its intended purpose.
  • Prototype the following functions in hlgame.h, with full implementation in hlgame.c. int checkGuess(int guess, int target) Description: checkGuess Returns -1 if guess is less than target, 1 if guess is greater than actual, 0 if equal void printEntryPrompt(int min, int max) Description: printEntryPrompt prompts the user to enter a value in the range of min (inclusive) and max (exclusive) with printf(). void printNumGuesses(int num) Description: printNumGuesses tells the user how many guesses are remaining with printf(). int takeEntry(int min, int max) Description: returns the user’s input. Uses scanf() and then uses getchar() to discard all characters until a line return is found. Valid entries are in the range of min (inclusive) and max (exclusive). If an invalid entry is detected, the function prints an error message and attempts to take entry again. int makeRandNum(int min, int max) Description: makeRandNum Returns a random int value in the range of min (inclusive) and max (exclusive) using rand. Also Seeds the random number using srand and time(0) before generating the value.

Sample Output |-----------------------------------| |Higher - Lower Number Guessing Game|

M. Wolverton 2021

You have 7 guesses remaining. Enter a number between 1 (inclusive) and 100 (exclusive). 50 Your guess is too high. You have 6 guesses remaining. Enter a number between 1 (inclusive) and 100 (exclusive). 25 Your guess is too low. You have 5 guesses remaining. Enter a number between 1 (inclusive) and 100 (exclusive).

Invalid entry. Enter a number between 1 (inclusive) and 100 (exclusive). ... You have 1 guesses remaining Your guess is too high. Enter a number between 1 (inclusive) and 100 (exclusive). 28 |-----------------------------------|

Correct, you got it!

You have won 1 time and lost 0 times. Would you like to play again? (y/n) n Thanks for playing!