Как я могу использовать операторы bool и if в C для получения этих результатов, я думаю, что мой код не дает требуемых результатов
Write C code to satisfy the following five requirements • Requirement 1: When MyInput1 has a value of 1, MyInput2 has a value of 0 and MyInput3 has a value of 0, then set MyOuput1 = 1, MyOuput2 = 0 and MyOuput3 = 0; • Requirement 2: When MyInput1 has a value of 1, MyInput2 has a value of 1 and MyInput3 has a value of 0, then set MyOuput1 = 0, MyOuput2 = 1 and MyOuput3 = 0; • Requirement 3: When MyInput1 has a value of 1, MyInput2 has a value of 1 and MyInput3 has a value of 1, then set MyOuput1 = 0, MyOuput2 = 0 and MyOuput3 = 1; • Requirement 4: For all other combinations of values for MyInput1, MyInput2, MyInput3, then set MyOuput1 = 0, MyOuput2 = 0 and MyOuput3 = 0; • Requirement 5: Lastly print the values of the following three variables to the user: MyOutput1, MyOutput2 and MyOutput3.
Что я уже пробовал:
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main() { bool MyInput1, MyInput2, MyInput3; bool MyOutput1, MyOutput2, MyOutput3; MyInput1 = 1; MyInput2 = 1; MyInput3 = 1; if (MyInput1&&!MyInput2&&!MyInput3) { MyOutput1 = 1; MyOutput2 = 0; MyOutput3 = 0; } else if (MyInput1&&MyInput2&&!MyInput3) { MyOutput1 = 0; MyOutput2 = 1; MyOutput3 = 0; } else if (MyInput1&&MyInput2&&MyInput3) { MyInput1 = 0; MyInput2 = 0; MyInput3 = 1; } else { MyOutput1 = 0; MyOutput2 = 0; MyOutput3 = 0; } printf("MyOutput1 = %d",MyOutput1); printf("MyOutput2 = %d",MyOutput2); printf("MyOutput3 =%d",MyOutput3); return 0; }