Thread: seriously been going at this all night and i cant figure out how to fix it

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    seriously been going at this all night and i cant figure out how to fix it

    Code:
    #include
    Code:
    <stdio.h>
    #include <ctype.h>
    #define MAX_GUESSES 6
    //function prototypes
    int main()
    {
    FILE* infile;
    int i;
    int numberofGames;
    char ans;
    char getguess;
    int compareguess(char guess, char ans);
    printf("Please enter the no of games you want to play");
    scanf("%d",& numberofGames);
    //variable declarations
    //prompt + get numgames
    //display instructions on how to play the game
        printf("Enter an letter in the range a to z\n");
        printf("I will try to guess your letter with in 6 guesses\n");
        printf("If you can guess my letter in 6 guesses, You Win!\n");
        printf("Would you like to play?\n");
        printf("Press 'Y' to play, or 'N' to quit\n");
        printf("Char Playgame\n");
    //connect to the file
    infile = fopen("letters.txt", "r");
    return
     0;
    }
    for
    (i=1; i<=numberofgames; i++)
    {
    //print current game (value of i)
    //get letter to guess from fscanf
    scanf(infile," %c",&ans);
    //printf to check the letters from file
    printf("%c",&ans);
    //call the play function to play a game
    numgames=playGame (ans);
    //it will return a 1 if the user wins and a 0 if the user took more than 6 guesses
    //condition here to print win or lose
    numgame==0'lose';numgame==1'win';
    }
    void Instructions()
    {  
     //instructions on how to play game
     
     
    }
     
    intplayGame (char ans); 
    {
            
    char guess;("numberOfGuess=0"), ("winOrLose=0");
            
    //call the play function to play a game
            numberOfGames=playGame (ans);
            
    //it will return a 1 if the user wins and a 0 if the user took more than 6 guesses
            
    //condition here to print win or lose
            numberOfGames==0("lose");
            numberOfGames==1("win");
        
        
    return 0;
    }
    chargetGuess()
    {
          
    //get the users' guess
          userGuess = toLower(userGuess);
    //change to lower case
          
    //return the users' guess
          
    return 0;
    }
    intcompareGuess(char guess, char ans)
    {
          
    //compare the guess and the answer
          compareGuess and ans;
          
    //return a 1 if they are the same
          
    return a 1 if ("both are the same");
          
    //print a message based on before or after alphabetically
          printf("message based on before or after alphabetically",&ans);
          
    //return a 0 if the guess and answer are not the same
          
    return a  0 if ("the guess and answer are not the same");
          
    return 0;} 

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    What is wrong? And please indent your code.

    A few hints:
    - You have active code outside your functions
    - Your main function ends without calling any of your other functions
    - You have incomplete function definitions (no return type specified) (seems like there is just a space missing)


    And some of your code just doesn't make any sense at all.
    Code:
    return a 1 if ("both are the same");
    numberOfGames==0("lose");
    char guess;("numberOfGuess=0"), ("winOrLose=0");
    Last edited by iceaway; 10-04-2011 at 05:49 AM.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    sorry about the indention thats from the copy past over from my compiler. but i try to build it and i get some rediculouse errors talking about ; where there shouldnt be or there needs to be i just cant figure it out and ive been working hard on it.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by jaymack View Post
    sorry about the indention thats from the copy past over from my compiler. but i try to build it and i get some rediculouse errors talking about ; where there shouldnt be or there needs to be i just cant figure it out and ive been working hard on it.
    I think you need to go read some tutorials on the basics of C. There is so much nonsense in your code that I don't even know where to start :-)

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    could you be more specific if you could point out whats wrong with them then i might be able to fix it i just have been looking at this so long i cant see anything to change.

  6. #6
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by jaymack View Post
    could you be more specific if you could point out whats wrong with them then i might be able to fix it i just have been looking at this so long i cant see anything to change.
    I think you should learn how to program C and then try to write it all over again from the beginning. Your code is not even remotely close to doing what you want, besides that fact that large parts of it is not even C syntax.

    How do you think the compiler should interpret this? A compiler is not a little gnome hiding in your computer who speaks english :-)
    Code:
    return a  0 if ("the guess and answer are not the same");
    Last edited by iceaway; 10-04-2011 at 05:56 AM.

  7. #7
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    kool man sorry i dont know programming like all of you but i was hoping for help but i guess not

  8. #8
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by jaymack View Post
    kool man sorry i dont know programming like all of you but i was hoping for help but i guess not
    I don't mean to scare you off, but I think you need to take another approach on learning C. Start out by reading some tutorials covering the absolute basics. You can start by looking right here on this site.

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Look you have been copying and pasting or hacking this code from a tutorial or example somewhere right? There is no conceivable way you could have written this yourself using some of the types and methods implied without having a good grasp of C already - And i think it's clear that some of it was / is pseudo code - intended for a reader to 'fill in the blanks'

    You should learn some very simple stuff properly - do not try and learn by wholseale copy and paste as you will find learning is totally unsatisfying, unenjoyable and proceeds at a crippled snail's pace.
    Last edited by rogster001; 10-04-2011 at 06:05 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    didnt hack anything i dont know much about c so i just used this and that because i thought it would fit and do it if i could hack you think my code would be the way it is also had a skeleton i was working off of

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Delete everything.

    Read this -> A development process

    Then start again, SLOWLY.

    If you've only added 3 lines, and there are some new errors you don't understand, then you have a decent pointed question to ask.

    Writing "code" (I use the term in the loosest possible sense) for several hours, then wondering why the errors won't stop scrolling is NOT a long term strategy.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Salem View Post
    Writing "code" (I use the term in the loosest possible sense) for several hours, then wondering why the errors won't stop scrolling is NOT a long term strategy.
    Sure it is. If your purpose is to be something other than a productive software developer, what you describe is a very effective long term strategy. The world does need people who can take our orders for fast food, after all.

    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starry night
    By swgh in forum C Programming
    Replies: 5
    Last Post: 12-11-2007, 03:26 PM
  2. Great night for T.V.
    By DISGUISED in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-20-2003, 11:53 AM
  3. This is my last night on this computer.
    By joshdick in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-12-2003, 01:33 AM
  4. how many pm's do you get a night?
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 11-25-2002, 12:44 AM
  5. Quite a night
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 05-09-2002, 09:39 PM

Tags for this Thread