so this is all part of a larger project of mine. the teacher told us to make a program that simulates a stop light/ intersection, we have to use ascii to "draw" the intersection then have the stop leights as numbers that change color based on wether the light is supposed to be red green or yellow. as you can see im not very far in the project ive only just got the ascii done and im kinda stuck on the countdown for each of the lights.
the program shouldnt display the previous numbers counted.
Do I take this to mean that there should be no output? Or should there be a countdown from 30 to 0, with a delay in between each iteration, then there is a "Screen Clear" and the new number is displayed? Something else? "Screen Clear" is in quotes because there are different ways of simulating it in a console program, two common ways being to display a bunch of newlines or executing a system("CLS") command. Someone might chime in saying not to use system("CLS") and there are good reasons. Consider a search of the forum regarding the "system" command, portability, etc., and ask your teacher how the screen should be cleared, if indeed it should.
Now to your main question. The program flow is going to go something like this.
for(int i = 30; i >= 0; i--)
// clear screen
// display i and anything else you need to display using cout
You don't have to clear the screen, just move the cursor back to the beginning of the line
True enough at this stage of the project and I hadn't thought of the "\r" option. It's going to get complicated soon though and quite a few things are going to be drawn, so might as well get the Clear Screen going. He'll need to do it eventually.
we have to use ascii to "draw" the intersection then have the stop leights as numbers that change color based on wether the light is supposed to be red green or yellow.
Toss out the potential portability concerns. This isn't going to be portable no matter what with the colors. Figure out what you need to use for the colors. I'm sure it will be some library. That library may have other options yuou can use. It all gets you farther and farther away from regular old standard C++.