Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A program that plays a stick-picking game: the program must be written in C. The game should greet the user, and then ask how many

A program that plays a stick-picking game: the program must be written in C. The game should greet the user, and then ask how many sticks to play with (must be an integer >=10), the user always goes first the user may be badly behaved: they might enter anything at anytime, so your program must be prepared to handle any input to determine how many sticks to start with, the game accepts either a command line parameter or program input. If a command line argument is given, make sure: there is exactly one such argument the argument is a valid integer If no command line arguments are present, read a number from the user, and make sure it is a valid, positive integer. If any errors are detected in choosing the initial number of sticks, print a message and exit. when the user is specifying how many sticks they want to pick, make sure they enter a valid number. This means: they don't just hit enter they enter an integer the integer is between 1 and 3 If there is any problem with their entry, ask them to re-enter, and keep trying until they make a valid entry. Note that you must use sscanf to test all entries. Do not simply compare the character to '1' '2 and '3' or use "atoi" The user might enter " 3" or "001" If sscanf accepts these as integers, then your program must also. On the users turn, ask the user how many sticks to remove, and remove those from the pile. On the computers turn, calculate the correct number of sticks to remove in order to ensure you will (hopefully) win the game. Play continues until there are no sticks left, at which point your program announces who won. You must show the set of sticks after each player's move. Show this as a set of pipes (|) side by side, followed by the number of sticks in (parenthesis). Algorithm Your algorithm for picking sticks is simple: given n remaining sticks, pick (n mod 4) sticks, unless (n mod 4)=0; in that case, pick 1 stick.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

a. How will the leader be selected?

Answered: 1 week ago