Decision tables: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 143: | Line 143: | ||
n |
n |
||
Sorry! I have no idea what to do now!</pre> |
Sorry! I have no idea what to do now!</pre> |
||
=={{header|C}}== |
|||
With flaky keyboard input:<lang C>#include <stdio.h> |
|||
#define N_COND 3 |
|||
#define COND_LEN (1 << N_COND) |
|||
struct { char *str, *truth;} |
|||
cond[N_COND] = { |
|||
{"Printer does not print", "1111...."}, |
|||
{"A red light is flashing", "11..11.."}, |
|||
{"Printer is unrecognised", "1.1.1.1."}, |
|||
}, |
|||
solu[] = { |
|||
{"Check the power cable", "..1....."}, |
|||
{"Check the printer-computer cable", "1.1....."}, |
|||
{"Ensure printer software is installed","1.1.1.1."}, |
|||
{"Check/replace ink", "11..11.."}, |
|||
{"Check for paper jam", ".1.1...."}, |
|||
}; |
|||
int main() |
|||
{ |
|||
int q, ans, c; |
|||
for (q = ans = c = 0; q < N_COND; q++) { |
|||
do { |
|||
if (c != '\n') printf("%s? ", cond[q].str); |
|||
c = getchar(); |
|||
} while (c != 'y' && c != 'n'); |
|||
ans = (ans << 1) | (c != 'y'); |
|||
} |
|||
if (ans == COND_LEN - 1) |
|||
printf("\nSo, you don't have a problem then?\n"); |
|||
else { |
|||
printf("\nSolutions:\n"); |
|||
for (q = 0; q < sizeof(solu)/sizeof(solu[0]); q++) |
|||
if (solu[q].truth[ans] == '1') |
|||
printf(" %s\n", solu[q].str); |
|||
} |
|||
return 0; |
|||
}</lang>output<lang>Printer does not print? y |
|||
A red light is flashing? n |
|||
Printer is unrecognised? y |
|||
Solutions: |
|||
Check the power cable |
|||
Check the printer-computer cable |
|||
Ensure printer software is installed</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.stdio, std.algorithm, std.exception, std.string, std.array, std.conv ; |
<lang d>import std.stdio, std.algorithm, std.exception, std.string, std.array, std.conv ; |
||
Line 220: | Line 270: | ||
Ensure printer software is installed |
Ensure printer software is installed |
||
Check/replace ink</pre> |
Check/replace ink</pre> |
||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution''':<lang j>require'strings' |
'''Solution''':<lang j>require'strings' |