Why does not my code print?

1

I would like to know why this code I am creating does not print anything when I compile it:

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

int main (void)

{
    int dadoacerto, vidadrizzt, vidaartemis, dadod, dadoa, CAd = 8, CAa = 5, dadoataqdr, dadoataart;

    scanf("%d\n%d\n%d", &dadoacerto, &vidadrizzt, &vidaartemis);

    srand( (unsigned)time(NULL) );

    dadod = rand() % dadoacerto;
    dadoa = rand() % dadoacerto;

    if(dadod>dadoa)
    {
        dadoataqdr = rand() % 8;//Drizzt ataca primeiro

        if( dadoataqdr>CAa)
        {
            vidaartemis = vidaartemis - dadoataqdr;
            printf("Drizzt %d", dadoataqdr);        
        }
    }   
    else if(dadoa>dadod)
    {
        dadoataart = rand() % 5 + rand() % 5;

        if(dadoataart>CAd)
        {
            vidadrizzt = vidadrizzt - dadoataart;
            printf("Artemis %d", dadoataart);
        }
    }
    else if (dadoa==dadod)
    {
        dadoataqdr = rand() % 8;//Drizzt ataca primeiro

    if( dadoataqdr>CAa)
        {
            vidaartemis = vidaartemis - dadoataqdr;
            printf("Drizzt %d", dadoataqdr);        
        }
    }

return 0;
}
    
asked by anonymous 20.04.2015 / 20:51

1 answer

1

Your program has some logic errors. I've run it here and found, I think, the main problem why your program is not printing an exit. The following is occurring when your program enters an if, for example the first one, it will have to test still to enter the internal if the condition is false the code with the printf will not be executed and the program will not be able to execute nor another command inside an else, so it will not print anything at the end. As I do not quite understand what the purpose of this program is a bit difficult to fix, but you just need to take a little bit more care with the if-esle logic.

One possible suggestion would be to combine the two conditions in an if only using the & & operator.

    
20.04.2015 / 21:26