vendredi 29 janvier 2021

Error "rand" was not declared in this scope

I'm having a problem with the rand() function in C.

The code looks something like this:

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

int main()
{
    int c = 10;
    int i = 0;
    int cn[10];

    srand(time(NULL));

    while(i < c)
    {
        cn[i] = rand() % 10 + 1;
        printf("%d ", cn[i]);
        i++;
    }
}

When I execute the code, i get this error: [Error] "rand" was not declared in this scope.

I think this is a stdlib issue, because if i don't include stdlib but i include cstdlib, it opens cstdlib and the error: [Error] "rand" was not declared in this scope, appears there too.

When i try to Run it only with cstdlib it opens a different Dev C++ window that looks like this:

enter image description here




Aucun commentaire:

Enregistrer un commentaire