School-Coding-Cpp/cicli_operatori/sensori.cpp

78 lines
2.0 KiB
C++

/*
AUTORE: Manuel Vichi 3^AIN
Sistema di allarme
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(void) {
int rifai = 1;
do {
int bit0 = 0, bit1 = 0, bit2 = 0, bit3 = 0, bit4 = 0, bit5 = 0, bit6 = 0, bit7 = 0;
// Imposta i sensori casualmente
srand(static_cast<unsigned int>(time(0)));
bit0 = std::rand() % 2;
bit1 = std::rand() % 2;
bit2 = std::rand() % 2;
bit3 = std::rand() % 2;
bit4 = std::rand() % 2;
bit5 = std::rand() % 2;
bit6 = std::rand() % 2;
bit7 = std::rand() % 2;
cout << "Stato sensori:" << endl;
if (bit0 == 1) {
cout << "Cucina: ALLARME ON" << endl;
}
else {
cout << "Cucina: ALLARME OFF" << endl;
}
if (bit1 == 1) {
cout << "Sala: ALLARME ON" << endl;
}
else {
cout << "Sala: ALLARME OFF" << endl;
}
if (bit2 == 1) {
cout << "Balcone: ALLARME ON" << endl;
}
else {
cout << "Balcone: ALLARME OFF" << endl;
}
if (bit3 == 1) {
cout << "Luci: ALLARME ON" << endl;
}
else {
cout << "Luci: ALLARME OFF" << endl;
}
if (bit4 == 1) {
cout << "Ingresso: ALLARME ON" << endl;
}
else {
cout << "Ingresso: ALLARME OFF" << endl;
}
if (bit5 == 1) {
cout << "Letto 1: ALLARME ON" << endl;
}
else {
cout << "Letto 1: ALLARME OFF" << endl;
}
if (bit6 == 1) {
cout << "Letto 2: ALLARME ON" << endl;
}
else {
cout << "Letto 2: ALLARME OFF" << endl;
}
if (bit7 == 1) {
cout << "Bagno: ALLARME ON" << endl;
}
else {
cout << "Bagno: ALLARME OFF" << endl;
}
cout << endl << "Vuoi ripetere l'operazione? Inserisci 1 (SI) o 0 (NO): ";
cin >> rifai;
cout << endl;
} while (rifai != 0);
return 0;
}