+ 1

Truth Table Generator wont show correct result when user inputs Logical NOT

New in C here. The code is a simple truth table generator with only 3 columns (p q result). The program works just fine, unless when the Logical NOT operator (!) is inputted. ------------------------------------------- The output Im getting when I enter: !p&q p q !p&q F F T F T T T F F T T F ------------------------------------ My desired Output: p q !p&q F F F F T T T F F T T F This is the code: https://www.sololearn.com/en/compiler-playground/c9lN95xU1dJO

3rd May 2024, 8:59 AM
Jade Tito
Jade Tito - avatar
3 odpowiedzi
+ 3
The problem stems from line 42 where sscanf is targeting the output to the wrong variables. Two of them are swapped. After that there is more work to be done to correctly evaluate the expression that contains a '!'. For app users, here is the link to the code: https://sololearn.com/compiler-playground/c9lN95xU1dJO/?ref=app
3rd May 2024, 1:57 PM
Brian
Brian - avatar
+ 1
why is there a need for user input? it just complicates the code if you just want a truth table. https://sololearn.com/compiler-playground/cgxRhfH3I14g/?ref=app
4th May 2024, 2:46 PM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li That would've been great but we were required to get the user input
6th May 2024, 12:55 AM
Jade Tito
Jade Tito - avatar