reseting for loop / automatic door code help

** New to website**
i want my code to be able to go from any "state" to opening just like a real life automatic door can but i dont know what to add to the for loop to do that. If it's a if statement i dont know what to put in the ( )
for c++ class help pls

here is the code:

#include <iostream>
#include <ctime>
#include <csignal>
using namespace std;

void wait_three_seconds() {
clock_t start = clock();
while ((clock() - start)/CLOCKS_PER_SEC < 3)
;
}
const int START = 0;
const int CLOSED = 1;
const int OPENING = 2;
const int OPEN = 3;
const int CLOSING = 4;
const int RESET = 5;

void signal_handler(int signal) {
cout << "Interrupt Received!\n";
}

int main() {
signal(SIGINT,signal_handler);
string input;
while (cin) {
cin >> input;
if (input == "quit") return 0;
if (input == input){
for(int state = START; state < RESET + 1; state++){
if (signal_handler = 1){
state = OPENING;
wait_three_seconds;
}
if (state = CLOSED){
cout << "The door is closed" << endl;
wait_three_seconds();
}
if (state = OPENING){
cout << "The door is opening" << endl;
wait_three_seconds();
}
if (state = OPEN){
cout << "The door is open" << endl;
wait_three_seconds();
}
if (state = CLOSING){
cout << "The door is closing" << endl;
wait_three_seconds();
}
if (state = RESET){
cout << "The door is closed" << endl;
wait_three_seconds();
}
}
}
}
}
Last edited on
Topic archived. No new replies allowed.