I'm to write a code in C to let the user enter the first and last characters of the word "fantastic". If he is correct for the two answers it should print "Well done", if he gets one wrong then it should print "one of your answers is incorrect" if he gets both incorrect i tell him to try again later.
Below is the code I tried which doesn't allow me to enter the second character and also gets the answer wrong.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word[] = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word \'fantastic\': ");
scanf("%c", &in1);
printf("\nPlease enter the last letter of the word \'fantastic\': ");
scanf("%c", &in2);
if (in1 == word[0], in2 == word[8]) {
printf("\nWell Done!\n");
}
else if (in1 == word[0], in2 != word[8], in1 != word[0], in2 == word[8]) {
printf("\nOne of your answers is incorrect!\n");
}
else {
printf("\nTry again next time!\n");
}
return 0;
}