Question: Code in C: I'm trying to write code for a pick up sticks game for an assignment. The user can only enter 1,2, or 3

Code in C:

I'm trying to write code for a pick up sticks game for an assignment. The user can only enter 1,2, or 3 sticks to pick from a pile. If two invalid numbers are entered in a row then the program is supposed to terminate. I'm having trouble figuring out how to get the program to accept only a 1,2, or 3. When I use the current code I have or try to use the variable I tied to scanf, the while loop considers any number entered as invalid. Even if a 1,2, or 3 is entered. What's a good way to write the code so it will compare the command line argument to either 1,2, or 3 and terminate after 2 incorrect tries in a row?

Here's the code I have:

Code in C: I'm trying to write code for a pick up

sticks game for an assignment. The user can only enter 1,2, or

#include int tolnt (char num[]) while(atoi(num) == ) printf( "Please enter a valid number n scanf(%s ,num); return atoi(num); int userTurn (int argc) char numStick[5] printf scant( %s, numStick); while(tolnt(numStick)x10) ("Welcome to pick up stick.InPlease enter the numbe . In ("Please enter a minimum of 10 sticks to play. In") printf scant( %s, ,numstick); int userTurn1 (int argc) int userNum[50]; printf( scanf("%d", userNum); while(argc != ll argc Please enter either 1,2, or 3 sticks to take. In != ll argc != "Your you can only take 1,2, or 3 sticks. Please printf( scanf("%d", userNum); supply ano In if(argc argc3) printf( That was a valid answer.In break; if(argc printf argc2 argc3) Please enter a valid answer of 1,2, or 3.n if(argc != l l l argc != 2 l l argc != ) printf scanf(d,userNum); You have two invalid entries in a row. Progran break

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!