This is what I need to do . I had goggle what is rand and srand but what i get is the rand and rand only showed random input number.
But what i read from the question is the light of the traffic need to be random.
So can the WORDS be random by using rand and srand ?
I'm struggle on this for few days. Can anyone give me some advice or hint how should i start ?
Thanks for your help !!!
Your program should generate status of the traffic light (“red”/ “green”/ “yellow”) randomly
to simulate its operation status. (Hint: apply rand( ) and srand( ) function)
Player will be prompted to enter his current car status either it is in “moving mode” or in
“stop mode”.
For example,
Enter your car status: (s-STOP/ m-MOVING):
Based on the player input and the traffic light status, your program should check if the player
breaks the traffic regulation. By default, each player will be given 10 marks once the game is
started. Player’s score will be decremented by 3 points if he breaks the regulation. In contrast,
he will be awarded 1 point if he obeys the regulation. However, no points will be deducted or
awarded if the traffic light is “yellow” regardless of the player’s car status.
Each player will be given 10 points as the game starts. If the user’s points is less than or equal
to zero, prompt the user by displaying relevant messages and terminate the game
automatically.
Display all possible informative messages based on different scenarios. Your program should
also calculate the player’s score and display his latest score on the screen. E.g. if the car is
moving when the light is “red”, display the message as follows:
Your car is moving.
The light is red.
Behave yourself!
Your score is decremented by 3 point!
Your latest score is 7.
I'm sorry.
I don't really understand what are you trying to tell me. Is it using the index value to represent the words/alphabet ?
do you mind to show me some example ?
line 33 - rand() is returning a number and the code is trying to assign this number directly to an array that contains strings. As Kemort mentioned above, the random number could be used as an index into the array, i.e. the [i] in numArray[i].
Since you only want a small subset of random numbers (0, 1 or 2), use the % modulus operator in conjunction with rand() to limit the possible values.