samedi 9 avril 2022

How do i get different value for each of the outputs? [duplicate]

i have to generate random number of antigen tests, then for each test i have to generate a number again, either 1 or 0. In this code, it generates a random value 0 or 1, but applies the value to every test. How do i make it different for each test? (we have to use functions)

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

int main()
{
    srand(time(NULL));
    int testResult();
    float positivePercentage(int, int);
    void displayResults(int,int,float);
    int result;
    int i;
    int negativeResult = 0;
    int positiveResult = 0;
    int numofTests;
    int c=0;

    srand(time(NULL));
    numofTests = 1+(int) rand()%100;
    printf("You have completed %d test today, and the results are as follows:\n",numofTests);

    for (i=1; i<=numofTests; i++)
    {

        //testResult(&result);
        printf("test %d: %d\n", i, testResult());

    }
return 0;
}
    int testResult()
{

    srand(time(NULL));
    return (int) rand()%2;
}



Aucun commentaire:

Enregistrer un commentaire