-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ7.cpp
More file actions
30 lines (25 loc) · 657 Bytes
/
Q7.cpp
File metadata and controls
30 lines (25 loc) · 657 Bytes
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
// 7. Write a function that simulates a traffic light system. The function should take the current light color (red, yellow, green) as input and print the corresponding action:
// "red" → "Stop"
// "yellow" → "Slow down"
// "green" → "Go"
#include <iostream>
#include <string>
using namespace std;
int main() {
string light;
cout << "Current Light: ";
cin >> light;
if (light == "red") {
cout << "Stop\n";
}
else if (light == "yellow") {
cout << "Slow down\n";
}
else if (light == "green\n") {
cout << "Go";
}
else {
cout << "Invalid light color!";
}
return 0;
}