this is my first programming assignment for C, and I am very confused on how to implement random numbers. In my program I have already created a struct student, and created an array with 10 of those students. Now I have to generate random ID numbers and test scores for those 10 students, but my teacher was never clear how to exactly do that. I am also not allowed to change the variables or function declarations. Here is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct student {
int id;
int score;
};
struct student *allocate() {
return calloc(sizeof(struct student), 10);
}
void generate(struct student* students){
/*
*Generate random ID and scores for 10 students, ID being between 0 and
* scores equal to (id* 10 % 50)
*/
}
int main() {
struct student *stud = allocate();
generate(stud);
return 0;
}
He also gives this instruction: "Write a function void generate(struct student* students) that populates the id and score fields of the array of 10 students passed as an argument. Each student should have an id that corresponds to their index in the array (i.e. the first student in the array should have id 0). If each student's id is x, the student's score should be (10 * x) % 50."
Aucun commentaire:
Enregistrer un commentaire