*Im trying to make a dice program using C for my university but ive been specifically asked by the lecturer not to modify the main function he has given me but i have no clue how i can add math commands to his function
float getRand() {
return rand() / (RAND_MAX+1.0);
}
to make this dice.
P.S. Im only learning so all of this is new
This is the task:
Write a "dice rolling" game. You are probably familiar with 6-sided dice, but some games use dice with 4, 6, 8, 10, 20, and 100 sides!
Make the computer pick a random number for a 6-sided die and a 20-sided die. Use the getRand() function, but do not modify it. Write an int rollDie(...) function to get a random value. have one integer argument for the value of the die (int number_of_sides), call the getRand() function. take the value it returns (a float between 0 and 0.999...) and do some math to transform that into an int between 1 and number_of_sides inclusive). return the number. Your int main() must contain only:
int main() {
srand( time(NULL) ); // init random
getRand(); // kick-start the random numbers
int value = 0;
value = rollDie(6);
printf("6-sided die: %i\n", value);
value = rollDie(20);
printf("20-sided die: %i\n", value);
getchar();
}