Page 1 of 1

I need help, without code. :D

Posted: Thu Nov 19, 2009 11:17 am
by Exutus
Yo and welcome to the frog's first post :lol:
I'm at work, on lunch time, can't go in IRC here so I registered to the forum.
Well, since I started learning C the other day, I thought it was pretty cool... I went through a few things, and just learned about loops. (*EDIT: Forgot to mention the language... it's C )

So, this post is to ask if you cuold shed me some light, without giving me the code right away, you see my little game below; I want to upgrade it.

If you can give me a well detailed picture, I would appreciate since I need to learn, so neither a direct asnwer or formula would do.

I want:

1) The program to count the number of times the user tried a number before finding the random one.
printf("Contrats, after % number of times, you found it", variable)

2) I want the program to ask if the user want to try another game, using booleen (always true, false = endgame)

and 3rd) I want it to be a 2 players game, someone enters the "random" number, and the other person tries to find it... BUT! We MUST be able to choose wether its gonna be a 1 player (random generated number) or 2 players.

:)
I need some help from you coders :shock2:

Code: Select all

/*

Less or More Mini-game-------------

*/


#include <stdio.h>
#include <stdlib.h>
#include <time.h>


int main ( int argc, char** argv )
{
    int guessNumber = 0, inputNumber = 0;
    const int MAX = 100, MIN = 1;

    // Generating the random number

    srand(time(NULL));
    guessNumber = (rand() % (MAX - MIN + 1)) + MIN;

    /* Loop of the program. It repeats until the user finds the guessNumber
    */

    do
    {
        // It asks for the number
        printf("What is the number ? ");
        scanf("%d", &inputNumber);

        // We compare the input number with the guessNumber

        if (guessNumber > inputNumber)
            printf("It's more !\n\n");
        else if (guessNumber < inputNumber)
            printf("It's less !\n\n");
        else
            printf ("Congrats, you found the mysterious number !!!\n\n");
    } while (inputNumber != guessNumber);

}

Re: I need help, without code. :D

Posted: Thu Nov 19, 2009 2:51 pm
by andrew
Do you mean something like this?
guess game.PNG
guess game.PNG (15.26 KiB) Viewed 846 times
This might also be really helpful to you:
Lecture 6: Solving Problems - Richard Buckland UNSW 2008

Re: I need help, without code. :D

Posted: Thu Nov 19, 2009 4:26 pm
by Exutus
Not really

1st, it asks "1 or 2 players ?"

If 1 player ---> the person plays against the computer, the computer generates a number (15 for instance), the player enter 21, the computer replies "Too high!", then the player tries 14, the computer replies "too low", then the player enter 15... The computer replies "Congrats, you found it after 3 tries!"

Then "Play again?"

Then it would re-play, still on the 1-player mode.
---

If 2 players ---> Let's say I enter a number for you to guess, it'll scanf my number, but then you have to try (no random number generating) and the game plays the same rules, if you get the number it then says "Congrats Player 2! You found the number that Player1 entered, it took you 5 times."

Then "Play again?"

Then it would re-play, still on the 2-players mode.

:)

Re: I need help, without code. :D

Posted: Thu Nov 19, 2009 5:12 pm
by Trask
int tries;
while(!answer)
{
cout << "number is too high/low";
tries++
}

if(answer)
{
cout << "You won after" << tries;
}

Horribly jumbled psuedo code... but the tries++ adds one to the variable 'tries' every time it loops through. I'm writing this rush style, but yeah... hopefully you get the point.

Re: I need help, without code. :D

Posted: Thu Nov 19, 2009 6:32 pm
by Exutus
What's up Trask
Hey isn't that for C++ ?

Re: I need help, without code. :D

Posted: Thu Nov 19, 2009 10:40 pm
by Trask
The code is a jumble, mostly C++. I'm tired as heck and I'm just answering the question. Bottom line is to add a +1 to a variable in a list of things you want to do when a user guesses wrong.

if(!answer)
{
guess = guess + 1;
}

Simply print out the 'guess' variable for the number of guesses.