#include <cs50.h>
#include <stdio.h>
#include <ctype.h>

int main()
    int iRandD1 = 0;
    int iRandD2 = 0;
    int totalD = 0;


    //use random numbers to assign values to each die

    iRandD1 = (rand() % 6) + 1;
    iRandD2 = (rand() % 6) + 1;

    if ((iRandD1 + iRandD2) == 7 || (iRandD1 + iRandD2) == 11)
        printf("player wins\n");

        printf("%d", totalD);


There is my code for a dice game that predicts the sum of the two dice when rolled. I include the ctype.h library for the srand(time()), I include but this error keeps coming up.

/home/ubuntu/workspace/fooling/ $ make dice
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    dice.c  -lcs50 -lm -o dice
dice.c:10:11: error: implicit declaration of function 'time' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
1 error generated.
make: *** [dice] Error 1

any help with the solution?


cs50.h includes itself stdlib.h, but in C99 you have to include it yourself too.

srand() is defined in stdlib.h

time() is defined in time.h.

The links are to cppreference.com.


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

Although if you fix that, you will get another error, because that's not the way to use time().

If you want to seed rand() with srand(), do


and you don't have to do it for every integer you want to generate.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .