asked 114k views
1 vote
write a c program to simulate the following system: an alarm system has three different control panels in three different locations. to endable th esystem, swithces in at least two of the panels must be in the on position. if fewer than two are in the on position, the system is disabled

1 Answer

1 vote

Answer:

Here's a C program that simulates the alarm system you described:

#include <stdio.h>

#include <stdbool.h>

// Function to check if the alarm system is enabled or disabled

bool isAlarmEnabled(bool panel1, bool panel2, bool panel3) {

int onCount = 0;

if (panel1) onCount++;

if (panel2) onCount++;

if (panel3) onCount++;

return onCount >= 2;

}

int main() {

bool panel1, panel2, panel3;

printf("Enter the status of Panel 1 (1 for ON, 0 for OFF): ");

scanf("%d", &panel1);

printf("Enter the status of Panel 2 (1 for ON, 0 for OFF): ");

scanf("%d", &panel2);

printf("Enter the status of Panel 3 (1 for ON, 0 for OFF): ");

scanf("%d", &panel3);

if (isAlarmEnabled(panel1, panel2, panel3)) {

printf("The alarm system is enabled.\\");

} else {

printf("The alarm system is disabled.\\");

}

return 0;

}

Step-by-step explanation:

This program takes the status of each of the three panels (ON or OFF) as input and checks if the alarm system is enabled or disabled based on the rules you provided.

answered
User Kenneth Fisher
by
8.1k points