From 9167e9ca6e043c1a19eba925a3fc3380877ed2b2 Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Fri, 25 Oct 2024 10:11:25 +0000 Subject: [PATCH] Upload files to "cicli_operatori" --- cicli_operatori/sensori2.cpp | 95 ++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/cicli_operatori/sensori2.cpp b/cicli_operatori/sensori2.cpp index e9435bb..ab9181b 100644 --- a/cicli_operatori/sensori2.cpp +++ b/cicli_operatori/sensori2.cpp @@ -3,24 +3,81 @@ AUTORE: Manuel Vichi Sensori */ #include +#include using namespace std; -int main() { - int sensori; - cout << "Inserisci il valore dei sensori (0-255): "; - cin >> sensori; - if (sensori < 0 || sensori > 255) { - cerr << "ERRORE! Il valore dei sensori deve essere compreso tra 0 e 255." << std::endl; - } - else { - bool bit3 = (sensori >> 3) & 1; - bool bit6 = (sensori >> 6) & 1; - if (bit3 || bit6) { - sensori |= (1 << 7); - } - else { - sensori &= ~(1 << 7); - } - cout << "Valore aggiornato dei sensori: " << sensori << endl; - } +int main(void){ + int b0, b1, b2, b3, b4, b5, b6, b7; + + do + { + cout << "b0 OFF/ON (0/1) " << endl; + cin >> b0; + } while(b0 < 0 || b0 > 1); + + cout << endl << endl; + + do + { + cout << "b1 OFF/ON (0/1) " << endl; + cin >> b1; + } while(b1 < 0 || b1 > 1); + + cout << endl << endl; + + do + { + cout << "b2 OFF/ON (0/1) " << endl; + cin >> b2; + } while(b2 < 0 || b2 > 1); + + cout << endl << endl; + + do + { + cout << "b3 OFF/ON (0/1)" << endl; + cin >> b3; + } while(b3 < 0 || b3 > 1); + + cout << endl << endl; + + do + { + cout << "b4 OFF/ON (0/1)" << endl; + cin >> b0; + } while(b4 < 0 || b4 > 1); + + cout << endl << endl; + + do + { + cout << "b5 OFF/ON (0/1)" << endl; + cin >> b5; + } while(b5 < 0 || b5 > 1); + + cout << endl << endl; + + do + { + cout << "b6 OFF/ON (0/1)" << endl; + cin >> b6; + } while(b6 < 0 || b6 > 1); + + cout << endl << endl; + + do + { + cout << "b7 OFF/ON (0/1)" << endl; + cin >> b7; + } while(b7 < 0 || b7 > 1); + + cout << endl << endl; + + if(b3==1 or b6==1) + b7=1; + int btot =b7pow(2,7)+b6pow(2,6)+b5pow(2,5)+b4pow(2,4)+b3pow(2,3)+b2pow(2,2)+b1pow(2,1)+b0pow(2,0); + cout << btot; + + + return 0; -} +} \ No newline at end of file