Results 1 to 2 of 2
  1. #1
    new to programing

    Member Since
    Jul 21, 2010
    Posts
    6
    new to programing
    Hey Guys, I really need some help here. I am new to programming and I reading a book that focused on people like me...."beginners, noobs..." you know. I have been stuck working on an exercise for the last 5 days and I have gotten it to what I would like for it to be but I AM STUCK!!!
    The exercise requires me to insert a count of how many times the user guesses before they get the correct answer.
    I get the one count, but for some reason I can get it to increment.
    I have looked around for the answer but the ones that I have found, touch on subjects that the book has not touched upon.
    Please if you can assist, it would be great.

    Here is the code as of last night:

    int randomNumber = 1;
    int userGuess = 1;
    int countGuesses = 1;
    int moreGuesse = 1;
    moreGuesse++;
    BOOL oneGuess = TRUE;
    BOOL guessing = TRUE;
    BOOL continueGuessing = TRUE;
    BOOL keepPlaying = TRUE;
    char yesNo = ' ';
    while (keepPlaying)
    {
    randomNumber = (random()%101);
    NSLog(@"The random Number to guess is: %i", randomNumber);
    continueGuessing = TRUE;
    while (continueGuessing)
    {
    NSLog(@"Pick a Number between 0 and 100.");
    scanf ("%i", &userGuess);
    fgetc(stdin);//remove CR/LF i.e extra character
    if (userGuess == randomNumber)
    {
    continueGuessing = FALSE;
    NSLog(@"Correct Number!");
    }
    //nested if statement
    else if (userGuess > randomNumber)//an else if statement
    {
    //user guessed too high
    NSLog(@"Your guess is too high");
    }
    else
    {
    //no reason to check if userGuess < randomNumber. It has to be
    NSLog(@"Your guess is too low");

    }
    //refactored from our Alice app. This way we only have to code once.
    NSLog(@"The user guessed %d", userGuess);

    if (oneGuess != randomNumber)
    {
    NSLog(@"You have guessed %d time", countGuesses);
    }
    else if (guessing > randomNumber)
    {
    NSLog(@"You have guessed %d times", moreGuesse);
    }
    }
    NSLog(@"Play Again? Y or N");
    yesNo = fgetc(stdin);
    if (yesNo == 'N')
    {
    keepPlaying = FALSE;
    }
    }

    Any assistance would be very helpfull, if your going to be discouraging and tell me that coding is hard and I should not attempt it...back off I have a keyboard and I am not afraid to use it.....

  2. #2
    new to programing

    Member Since
    Jul 21, 2010
    Posts
    6
    New to Programing
    Hey Guys, I really need some help here. I am new to programming and I reading a book that focused on people like me...."beginners, noobs..." you know. I have been stuck working on an exercise for the last 5 days and I have gotten it to what I would like for it to be but I AM STUCK!!!
    The exercise requires me to insert a count of how many times the user guesses before they get the correct answer.
    I get the one count, but for some reason I can get it to increment.
    The count has to increment by one every time that a gues is done incorrectly.
    I have looked around for the answer but the ones that I have found, touch on subjects that the book has not touched upon.
    Please if you can assist, it would be great.

    Here is the code as of last night:

    int randomNumber = 1;
    int userGuess = 1;
    int countGuesses = 1;
    int moreGuesse = 1;
    moreGuesse++;
    BOOL oneGuess = TRUE;
    BOOL guessing = TRUE;
    BOOL continueGuessing = TRUE;
    BOOL keepPlaying = TRUE;
    char yesNo = ' ';
    while (keepPlaying)
    {
    randomNumber = (random()%101);
    NSLog(@"The random Number to guess is: %i", randomNumber);
    continueGuessing = TRUE;
    while (continueGuessing)
    {
    NSLog(@"Pick a Number between 0 and 100.");
    scanf ("%i", &userGuess);
    fgetc(stdin);//remove CR/LF i.e extra character
    if (userGuess == randomNumber)
    {
    continueGuessing = FALSE;
    NSLog(@"Correct Number!");
    }
    //nested if statement
    else if (userGuess > randomNumber)//an else if statement
    {
    //user guessed too high
    NSLog(@"Your guess is too high");
    }
    else
    {
    //no reason to check if userGuess < randomNumber. It has to be
    NSLog(@"Your guess is too low");

    }
    //refactored from our Alice app. This way we only have to code once.
    NSLog(@"The user guessed %d", userGuess);

    if (oneGuess != randomNumber)
    {
    NSLog(@"You have guessed %d time", countGuesses);
    }
    else if (guessing > randomNumber)
    {
    NSLog(@"You have guessed %d times", moreGuesse);
    }
    }
    NSLog(@"Play Again? Y or N");
    yesNo = fgetc(stdin);
    if (yesNo == 'N')
    {
    keepPlaying = FALSE;
    }
    }

    Any assistance would be very helpfull, if your going to be discouraging and tell me that coding is hard and I should not attempt it...back off I have a keyboard and I am not afraid to use it.....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Programing Language
    By Kax in forum OS X - Development and Darwin
    Replies: 4
    Last Post: 04-24-2010, 01:23 PM
  2. Programing Language Help
    By bingsgo in forum Web Design and Hosting
    Replies: 5
    Last Post: 01-26-2009, 02:49 PM
  3. Programing on the Mac
    By hojkoff_101 in forum OS X - Development and Darwin
    Replies: 4
    Last Post: 12-16-2008, 08:24 PM
  4. software for programing
    By zwill in forum OS X - Operating System
    Replies: 7
    Last Post: 08-21-2008, 04:29 AM
  5. Assembly Programing?
    By FishStickBoy in forum OS X - Development and Darwin
    Replies: 13
    Last Post: 02-15-2005, 12:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •