Solved

# Design an algorithm that plays game of fork with limited chances

Posted on 2003-03-31
Medium Priority
180 Views
the game is guessing a single number that the computer randomly hides within a give range lets say the user enters  a number we output results. if it is not clear dont hesitate to ask me.
dapro1284@yahoo.com
0
Question by:switloic
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

Author Comment

ID: 8240554
to modify the game --
0

LVL 10

Accepted Solution

substand earned 200 total points
ID: 8240799
are you using any specific language?  here's a generic example in c:

#define MINNUM 1
#define MAXNUM 10

int randomInt(int low, int high);

int main()
{
int seed=time(NULL);
int compNum=randomInt(MINNUM,MAXNUM);
int userNum;

srand(seed);

printf("Pick Num between %d and %d.", MINNUM,MAXNUM);
scanf("%d",&userNum);

if (userNum==compNum) printf("You win!");
else printf("You lose!  The number was %d", compNum);

return 0;
}

int randomInt(int low, int high)
{  int k;
double d;
d = (double) rand() / (double)(RAND_MAX + 1);
k = d * (high – low + 1) + low;
return k;
}
0

LVL 24

Expert Comment

ID: 8241917
> to modify the game --

Have computer use random number to decide which program code to execute next. This is not a fork operation. It is beneficial for modeling. As a game, the human types text, and the computer (doctor) can reply with different phrases each time, even if user re-enters tha same thing.
0

Expert Comment

ID: 9446618
switloic:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

LVL 10

Expert Comment

ID: 9447758
considering my answer is the only complete one, i vote for myself receiving points.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
###### Suggested Courses
Course of the Month14 days, 20 hours left to enroll