C++ Program: [Switch] Traffic Light Simulation: Red, Yellow, Green

By: Prof. Dr. Fazal Rehman Shamil | Last updated: July 25, 2024

Write a C++ program for Traffic Light Simulation: Red, Yellow, Green.

Possible Outputs

Output#1

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 1
Current light is Red

Output#2

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 2
Changing light to Yellow

Output#3

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 1
Current light is Yellow

Output#4

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 2
Changing light to Green

Output#5

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 1
Current light is Green

Output#6

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 2
Changing light to Red

Output#7

Traffic Light Simulation Menu:
1. Show Current Light
2. Change Light
3. Exit
Enter your option (1-3): 3
Exiting the traffic light simulation. Thank you!