Here's a blood typing program I wrote on a sick bag on an airplane; it's been giving me mounds of trouble. The latest development is that when I try to print the blood types it doesn't show anything.
Sorry for making your eyes bleed, I'm not really going for efficiency here and I've hackneyed more solutions that I can count.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char bloody [3] = "O- ";
void get_blood_type() {
if ((rand() % 1) == 1)
if ((rand() % 1) == 1)
bloody [0] = 'A';
if ((rand() % 1) == 1)
if ((rand() % 1) == 1)
bloody [0] = 'B';
if ((rand() % 1) == 1)
bloody [0] = '+';
if ((rand() % 1) == 1)
if ((rand() % 1) == 1)
bloody [0] = "AB+";
if ((rand() % 1) == 1)
bloody [0] = "AB-";
return;
}
int verify(char recp [3], char blood [3]) {
int eval [3];
if (blood [1] == 'B') {
eval [0] = 1;
eval [1] = 1;
if (blood [2] == '+')
eval [2] = '1';
else
eval [2] = '0';
}
else {
if (blood [0] == 'O') {
eval [0] = 0;
eval [1] = 0;
}
else if (blood [0] == 'A') {
eval [0] = 1;
eval [1] = 0;
}
else if (blood [0] == 'B') {
eval [0] = 0;
eval [1] = 1;
}
if (blood [1] = '+')
eval [2] = 1;
else
eval [2] = 'O';
}
int rval [3];
if (recp [1] == 'B') {
rval [0] = 1;
rval [1] = 1;
if (recp [2] == '+')
rval [2] = '1';
else
rval [2] = '0';
}
else {
if (recp [0] == 'O') {
rval [0] = 0;
rval [1] = 0;
}
else if (recp [0] == 'A') {
rval [0] = 1;
rval [1] = 0;
}
else if (recp [0] == 'B') {
rval [0] = 0;
rval [1] = 1;
}
if (recp [1] = '+')
rval [2] = 1;
else
rval [2] = 'O';
}
int z = 0;
for (int i = 0; i == 2; i++)
if (eval [i] <= rval [i])
z++;
if (z == 3)
return 1;
return 0;
}
int main() {
char answer;
int answerint;
char donor [3];
char recip [3];
printf ("Hello! I'm going to ask you a few questions about blood typing. Answer lowercase \"y\" or \"n\" for yes\
or no respectively; answer \"q\" to quit.\n");
for (;1==1;) {
get_blood_type();
for (int i = 0; i == 2; i++) {
donor [i] = bloody [i];
}
get_blood_type();
for (int i = 0; i == 2; i++) {
recip [i] = bloody [i];
}
printf("Can %s donate to %s?\n", donor, recip);
scanf("%c", &answer);
if (answer == 'y')
answerint = 1;
if (answer == 'n')
answerint = 0;
if (answer == 'q')
return 0;
if (answerint == verify(recip, donor))
printf("Good job! Next question.\n");
else
printf("Nope.\n");
}
}