# Thread: number guessing game, no idea where to start

1. ## number guessing game, no idea where to start

hey guys

so I made the stupid mistake of taking a course this year becuase one of my friends took it last year and found it dreadfully easy. Unfortunatly the course format was changed this year, and we are learning to program in C (last year they learned the difference between a ball-mouse and an optical mouse).

My assignment is this: you will write a computer program that actually plays the game. it will make smart guesses until it finds the right answer. you will write your program in the C programming language.
the rules:
1/ the user will pick a number between 1 & 100 (but not tell the computer what it is)
2/ the computer will make a guess
3/the user will tell the computer whether its guess was too hight, to low, or right on
4/ steps 2 and 3 repeat until the computer guesses right, when it will output "I got it!""

there is a good way to play this game - a smart player will always cut the range of possible answers in half with every guess

the codes that will tell the computer how to evaluate it's guess are:
input of 0 means: right on
input of 1 means: too low
input of 2 means: too high

I know that I'm going to have to establish variables, (ints upper lower and guess?) and then have a loop where the comptuer calculates what the guess should be based on the last input, then guesses, then gets feedback about whether it guessed too high, low or right on.
then break the loop.

but i don't have a clue how to start any of it. back in the day when I was in grade 10, I couldn't get a handle on QBasic, I'm not surprised that even 5 years later, this is still beyond me.

2. psuedo

Code:
```random_number
until (enternedNumber = random_number)
if enternedNumber > random_number
output too high
if enternedNumber < random_number
output too low
enternedNumber = input;
when done
output just right.```

3. Have you considered the possibility that this isn't the course for you.

People come here to learn stuff, not get free get out of jail cards for taking what they thought would be an easy course.

Cos if you think this is tough, you're in for one hell of a surprise in a couple of months.

OK, big assumption time.
I'm assuming that you didn't bunk off the introductory "hello world" lessons which would have taught you the basic printf() and scanf() usage necessary to prompt the user and read some input.
If you could at least manage that, it would be a start...

4. Actually, the rest of the course has been pretty easy (HTML, learning about encoding, etc.). There's no doubt in my mind that this isnt' the path that I'm meant to take in life, but this IS just one assignment, not an entire course on programming. This is the only program that we're going to have to write (the year is over in about a month).

I don't know how much good it would do to justify myself to you, becuase you seem to be set in your opinion that I'm not deserving of help (which may be entierly true -- i'm not denying that it's low to ask for help like this).

and chris -- thanks. Hopefully when I get home from school again tonight, I can sit down with your suggestion (i even tried writing the pseudo code myself, but was still a little lost), and try to work through things. =)

5. Originally posted by karin
and chris -- thanks. Hopefully when I get home from school again tonight, I can sit down with your suggestion (i even tried writing the pseudo code myself, but was still a little lost), and try to work through things. =)
The pseudo code is backwards from your description:
you will write a computer program that actually plays the game. it will make smart guesses until it finds the right answer.
Chris' code is the computer thinks of a number (hence "random") and you do the guessing.

You can use it to a degree, but rewrite it to process the correct algorithm.

6. ok. so i've written what I hope is something approaching the program that i should have.

however, i'm trying to compile it, and keep getting the error "wrong # args in fucntion call", at which point it aborts the compile.

i looked around online but couldn't really find anything that would help me figure out what's wrong.

what does it mean? (i mean, wrong number of arguments in fuction call, right? but what does THAT mean?)

7. >i mean, wrong number of arguments in fuction call, right? but what does THAT mean?

Here is an example.
Code:
```#include <stdio.h>

int foo(int x, int y)
{
printf("x = %d, y = %d\n", x, y);
return x + y;
}

int main(void)
{
int result = foo(4); /* ERROR - too few arguments */
printf("result = %d\n", result);
return 0;
}```

8. It's simply a matter of being able to count

Code:
```void foo ( int a, int b ) {  // expects 2 args
}

...

int main ( ) {
foo( 1, 2, 3 );  // gets 3 args
return 0;
}```
So find the function it is complaining about, and compare how you're using it with how it is declared.

9. sorry for incorrect psuedo code (oxymoron), I misread the description, WaltP is write, it is backwards from your description.

10. Originally posted by karin
ok. so i've written what I hope is something approaching the program that i should have.

however, i'm trying to compile it, and keep getting the error "wrong # args in fucntion call", at which point it aborts the compile.

i looked around online but couldn't really find anything that would help me figure out what's wrong.

what does it mean? (i mean, wrong number of arguments in fuction call, right? but what does THAT mean?)

Curious as to whether you solved your problem. If not it would be helpful if you post your code. The board has a policy against doing homework, but your attempting it so....I for one would like to C what you got.