[Solved] C RPG game for my homework


Here are the issues in your code. First, as suggested in the comments, you don’t have to call srand on every iteration, just once upfront – that sets the random seed for your current program execution and here it is enough to do it once,

int main()
{

srand(time(NULL));

Secondly, you’re using wrong symbols for the percent character – what you’re using, a single % indicates type that is going to be outputted. You need to use %% instead,

printf("\nHeroj ima 100 HP\nNeprijatelj ima 100 HP\n1-napad    macem(80%% pogodak, 10-15 dmg\n2-napad munjom(50%% pogodak, 20-30 mg))");

Finally, you define (and declare) the functions without the extra parentheses (also, as mentioned in the comments) i.e. it’s not

int rand_int_mac() (int n) 

but

int rand_int_mac(int n) 

Same for munja.

Also, if you want your sword damage to be between 10 and 15 you need to change your random number generator function. Currently it produces numbers between 10 and 19. To do so use

udarac=rand_int_mac(6);

instead of

udarac=rand_int(10);

This will add a number between 0 and 5 to 10 in your function rand_int_mac and produce damage in the target interval. For thunder it would be

int rand_int_munja(int n)
{
    return rand()%n + 20;
}

…instead of + 10 and should be called as rand_int_munja(11).

solved C RPG game for my homework