dimanche 27 février 2022

Generate double random numbers? C++ [duplicate]

I'm a first semester comp sci student working on an assignment. The assignment is seemingly asking for double random numbers however the professor has only shown how to find integers from a random number generator using rand and srand. Any tips on this? a. Write a function to simulate a single shot. It should use the following declaration:

void shoot(bool &targetAlive, double accuracy);

This would simulate someone shooting at targetAlive with the given accuracy by generating a random number between 0 and 1. If the random number is less than accuracy, then the target is hit and targetAlive should be set to false. You need to generate random numbers.

For example, if Bob is shooting at Charlie, this could be invoked as:

shoot(charlieAlive, 1.0);

Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step b.




Aucun commentaire:

Enregistrer un commentaire