Hi, i'm new to C++, i was given an assignment to create a simple program for traffic control. i'm trying to find out how should i output data at a specific time, for e.g a driver approaches an intersection, the yellow light will flash indicating that he needs to slow down and then the red light to stop before taking a route. is there any function i can use to output red light a few seconds after yellow light. or does anybody have an idea to do it differently. i'd appreciate it if you just tell me what i need to kno and then i reasearch it myself.. thanks
im trying to understand this but its a bit difficult.. can you explain a bit more please. im not sure if you really understood what i wanna do or if its just me..
// indicating driver should slow down when yellow light flashes
cout << "Yellow Light\n";
// indicating driver to stop before taking any routes at intersection
cout << Red Light\n";
what i wanna do is after yellow light prints i wanna output Red Light literally 5 seconds after yellow light has printed to screen. the 5 seconds will be for the time driver takes after slowing down n reaching the intersection. is this possible or is there another way to go about this.
Yes. Like Duoas said, you can use time() to get the time when you output the yellow light, then check time() to see how many seconds have elapsed. If it is at least 5, output red light.
If you're new to c++ then I think you should not worry about the time, or the graphics: all of this will come with the libraries you will use. They all will have different time management functions and everything..
Also just have a look over std::sleep