Decision tables: Difference between revisions

mNo edit summary
Line 143:
n
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}}==
<lang d>import std.stdio, std.algorithm, std.exception, std.string, std.array, std.conv ;
Line 220 ⟶ 270:
Ensure printer software is installed
Check/replace ink</pre>
 
=={{header|J}}==
'''Solution''':<lang j>require'strings'
Anonymous user