The Furious Angels
FA Discussion => Off Topic => Topic started by: Avzeke (Khr0n1k) on March 27, 2008, 12:02:00 am
-
Do any you guys know C? I have this extra credit assignment that is supposed to be hard, for us, and I really need to do it so I can make sure I get an A this semester. It is a programming 1 class so nothing really advanced if any of you guys can help. This is the assignment paper.
Computer Programming I
Extra Credit Assignment
20 points (ALL or NOTHING)
Write a program that will allow the user to play a guessing game with the computer. The
program should present the user with two options:
1. Computer thinks of number, user guesses
2. User thinks of number, computer guesses
The number should be an integer between 1 and 100.
Option 1:
When the computer "thinks" of a number, it will generate a random number between 1 and
100 and then ask the user to guess. While the user's guess is not accurate, a message of
"Too high" or "Too low" will be displayed followed by a prompt for another guess. Once the
guess is correct, a message will be displayed indicating the correct guess and the fact that
the user has won. Option 2:
User enters the a number. The computer will use the following strategy to guess the
number:
a. Start with a guess in the middle (ie 50)
b. While guess is not correct
i. If guess is too high, guess the number half way between current guess and the
highest "low" guess made so far.
ii. If guess is too low, guess the number half way between current guess and the
lowest "high" guess made so far.
c. Once the guess is accurate, a message will be displayed indicating the correct guess
If you guys could give some help I would appreciate it greatly!
-
Seriously, Yea I can for sure help with this. I just finish coding my own shell in C. When is it due by?
-
Wednesday, which is the 2nd of April I believe. Thanks Eroz!
-
So I just sat down and coded it out. Took me about an 1 to do it, assuming its console and POSIX C based. I would say this is my best coded program, then again its one of the shortest ones too. Hooray Switch/Case. So any time just send an IM to EBiohazard and I can try and help.
Some key C functions to use.
fgets and atoi
rand (Be sure to use srand while using rand or you'll always get the same number.)
(int) (X) (to convert a floor back into a int.)
You only need stdio.h and stdlib.h too.
This would have been so much easier in Python.
-
*nocry faints
-
*yells for broin to quickly administer mouth to mouth as I surely wont do it. :)*
too bad this isn't visual or q basic I know those 2 much better than I know C