Thread: Scoreing System

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    11

    Scoreing System

    Now that the basic elements of my program are working, I'd like to implement new features. I'm trying to put in a scoring system, by where you get 10 points for every mine you hit.

    I've made a bit of test code to show my problem, basically it shows something like 4214848.

    Code:
    #include <stdlib.h>
    int player_score;
    
    main ()
    {
        int i=5;
        while (i--)
        {
            player_score=player_score+10;
            printf("Total Score: %d\n\n", &player_score);
            system("PAUSE");
        }
    }
    The while and system("PAUSE") aren't in my program, just used to show my problem. Basically, I want it to add 10 everytime you hit a mine, but it shows something like this instead.

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    player_score is not initialized, also you're printing the address of player_score rather then the value at that address, with your printf statement, remove the address operator.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Your problem is that player_score isn't initialized. In C++, variables contain 'garbage' when they are first declared, until you initialize them (i.e. set them to 0).

    Code:
    int player_score = 0;
     
    or
    int main()
    {
    player_score = 0;
    (...)
    }
    **EDIT** And yeah, the address thing too.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    > printf("Total Score: %d\n\n", &player_score);
    You want to initialize player score and instead of using the address of operator (&) do this:
    Code:
    printf("Total Score: %d\n\n", player_score);
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    11
    Oh, didn't know that was causing the problem.

    Thank you so much.

  6. #6
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    if you want to use &(with variablename) use this
    Code:
    int main()
    {
    int *p-L,i=5;
    while(i--)
    {
    
    printf("score=%i",*&p-L);
    //.........
    }

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int main()
    {
    int *p-L,i=5;
    That isn't even legal, to say nothing of it even having a prayer of compiling.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 01:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM