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.
And this is my main code for rand but it is not working for the rand part.
Can anyone give me some advice??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include<iostream>
#include<string>
#include <stdlib.h>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
const int sizeArray = 3;
string numArray[sizeArray] = { "red", "yellow", "green" };
char status;
numArray[0] = "red";
numArray[1] = "yellow";
numArray[2] = "green";
cout << "Enter your status of your car:\n";
cin >> status;
do
{
if (status == 's')
cout << "Your car is not moving.\n";
if (status == 'm')
cout << "Your car is moving.\n";
} while (!(status == 's' || status == 'm'));
for (int i = 0; i <= sizeArray ; i++)
{
numArray[i] = rand();
cout << numArray[i] << endl;
}
system("pause");
return 0;
}
|