Thread: need some help

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    8

    Question need some help

    ok heres the code to the game i`m making so far =/
    #include <stdio.h>
    main()
    {
    int health;
    int shot;





    for (health = 100; health != 0; health--)
    {
    printf("take a shot\n");
    scanf("%d", &shot);
    health = health - shot;
    printf("now health is %d\n", health);

    }
    printf("you shot him\n");


    now as you can see when ever the health is negative the game still continues now, i need to know whot to make it were when ever its a negative number (any) to end the loop
    thnx
    oh and sorry for not having the coding tags or whatever

    -eldian()
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    for (health = 100; health != 0; health--)

    How about:

    for( health = 100; health > 0; health -= shot )

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

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    8

    thnx for the reply but its still not doing what its supposed to

    well man thnx for the code it definlty exists when its a negative number but now it doubles the number like when i do 1 it`ll do 1 at first then it will start to goto 2 and decrease that away

    -eldian()

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    8

    got it

    never mind bro i got it, hey thnx thoe , you guided me in the right direction!
    -eldian()

Popular pages Recent additions subscribe to a feed