Question: #include using namespace std; int main(){ char ch[2]; int m, n; int k; int c = 0; while(true){ cout < < 1.Operate the elevator ;
#include using namespace std; int main(){ char ch[2]; int m, n; int k; int c = 0; while(true){ cout << "1.Operate the elevator "; cout << "2.Quit "; if (c == 0) cout << "The elevetor is at basement "; else { cout << "The elevator is at floor " << c << " "; } cout << "Enter choice:"; cin >> k; if (k == 2){ break; } if (k == 1){ cout << "Enter your floor (0,1,2):"; // 0- Basement cin >> n; int valid = 0; cout << "Enter which floor you want to go:"; cin >> m; if (c == 0) cout << "The elevetor is at basement "; else { cout << "The elevtor is at floor " << c << endl; } if (c == n){ cout << "The Elevator(E) is now open 'O' "; if (m > c){ cout << "The Elevator(E) is U "; cout << "The Elevator(E) is now at " << m << endl; c = m; } if (m < c){ cout << "The Elevator(E) is D "; cout << "The Elevator(E) is now at " << m << endl; c = m; } } else { if (n > c){ cout << "The Elevator(E) is U "; cout << "The Elevator(E) is now at " << n << endl; cout << "The Elevator(E) is now open 'O' "; cout << "The Elevator(E) is now close 'C' "; c = n; if (m > c){ cout << "The Elevator(E) is U "; cout << "The Elevator(E) is now at " << m << endl; cout << "The Elevator(E) is open 'O' " << endl; c = m; } if (m < c){ cout << "The Elevator(E) is D "; cout << "The Elevator(E) is now at " << m << endl; cout << "The Elevator(E) is open 'O' " << endl; c = m; } } } } } }
Can this be simplifed further by designating U as going up one floor and 2U as going up two floors. In the same fashion, going down one floor is D and the two floors, 2D.?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
