dimanche 18 octobre 2015

user-defined function for random number generator in C output incorrect

For this program we have to create a user defined function to return 25 random variables from a value of 60-100, but when I run the program all 25 values are the same. I'm pretty new at programming and I think the error resided in where the user-function is defined, because I think instead of running the variable 25 times, its just running once and printing that first value 25 times. But I don't know how to actually go about fixing it :(

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

    int get_value (int Random);

    int main (){
     srand(time(NULL));//to randomize the number after each run
    int Random = rand()%40+60;

    printf("These are the temperatures for the day\n");
      int temp[25], i;
        for (i=0;i<25;i++) 
            {
            temp[i]=Random; 
       printf("%d\n",temp[i]);
    }
    return 0;
    }

    int get_value (int Random)
    {
        Random=rand()%40+60;
    }




Aucun commentaire:

Enregistrer un commentaire