1
I wonder why this code I’m creating doesn’t 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;
}
When you compile or when you run? You’re probably not entering any
if
. Put aelse
to test– Lucas
The first thing the program does is
scanf()
. Make sure you enter 3 values so the program doesn’t get stuck on this statement.– pmg
When I click on "compile & run" in C++ DEV, do not print any value, only the option for input of scanf values
– Gabriel Vinicius
Yes, scanf() is correct
– Gabriel Vinicius