-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraffic light
63 lines (45 loc) · 1.2 KB
/
traffic light
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
int main(){
std::cout << "please enter your conditons :" << std::endl;
std::string condition1;
std::string condition2;
std::cin >> condition1 >> condition2;
bool greenlight{false};
bool redlight{false};
bool yellowlight{false};
bool policestop {false};
if(condition1 == "greenlight"){
greenlight = true;
}
if(condition1 == "redlight"){
greenlight = true;
}
if(condition1 == "yellowlight"){
greenlight = true;
}
if(condition2 == "policestop"){
greenlight = true;
}
else {
std::cerr << "please enter valid conditons" << std::endl; }
if(greenlight && policestop){
std::cout << "stop!" << std::endl;
}
else if(greenlight && !policestop){
std::cout << "GO" << std::endl;
}
else if(yellowlight && !policestop){
std::cout << "stop but start vehicles engine only" << std::endl;
}
else if(yellowlight && policestop){
std::cout << "stop and do not start vehicle engine " << std::endl;}
else if(redlight){
std::cout << "STOP!!" << std::endl; }
else {
std::cout << "stop" << std::endl;
}
return 0;
}
Footer
©