Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

image text in transcribed

#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

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

Step: 3

blur-text-image

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

Cite some of the contemporary challenges facing HRD professionals

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago