I just started attending an C basic course. Today I had this problem.
Why does entering Y and N with the "OutputF()"-function yield different results as passing Y an N directly?
printf("%d", OutputF(InputF(), InputF()));
printf("%d", OutputF('Y', 'N'));
Here is the whole code:
#include<stdio.h>
char InputF(void) {
char a = getchar();
while (getchar() != '\n');
return a;
}
int OutputF(char Input1, char Input2) {
if (Input1 == 'y' || Input1 == 'Y')
if (Input2 == 'y' || Input2 == 'Y')
return 200;
else
return 300;
else
if (Input2 == 'y' || Input2 == 'Y')
return 400;
else
return 500;
}
int main(void)
{
printf("%d", OutputF(InputF(), InputF()));
printf("%d", OutputF('Y', 'N'));
return 0;
}