Welcome to Westonci.ca, the ultimate question and answer platform. Get expert answers to your questions quickly and accurately. Our platform offers a seamless experience for finding reliable answers from a network of experienced professionals. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

Write a program of three groups of emergency responders. Each group has a emergency answer button and indicator light. The indicator light of the person who first presses the emergency answer button will be on, and then the indicator light will not response.

Sagot :

#include

using namespace std;

int main() {

// Set up 3 groups of responders
int group1Button = 0;
int group1Light = 0;

int group2Button = 0;
int group2Light = 0;

int group3Button = 0;
int group3Light = 0;

// Keep running until someone presses a button
while(group1Button == 0 && group2Button == 0 && group3Button == 0) {

// Check if group 1 presses button
if(group1Button == 1) {

// Turn on group 1 light
group1Light = 1;

// Don't turn on other lights
group2Light = 0;
group3Light = 0;

// First responder, don't wait for buttons
break;

}

// Check if group 2 presses button
if(group2Button == 1) {

// Turn on group 2 light
group2Light = 1;

// Don't turn on other lights
group1Light = 0;
group3Light = 0;

// First responder, don't wait for buttons
break;

}

// Check group 3 button
if(group3Button == 1) {

// Turn on group 3 light
group3Light = 1;

// Don't turn on other lights
group1Light = 0;
group2Light = 0;

// First responder, don't wait for buttons
break;

}

}

// Print out lights
cout << "Group 1 light: " << group1Light << endl;
cout << "Group 2 light: " << group2Light << endl;
cout << "Group 3 light: " << group3Light << endl;

return 0;
}
We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.