I tried to stay away as long as possible, but to no avail. 
This time, it's a problem where a user enters a letter (b,g,o,y) and is given a return statement depending on the letter (char) entered.
The user is prompted for a letter, and the program takes in to consideration a lower or upper case. If the letter entered does not match any case, an unknown is returned - a match returns it's corresponding statement.
My problem today is that no matter what, it returns the default - unless I change the 'x' to one of the 4 letters. Any hints are appreciated.
Thank you.
This time, it's a problem where a user enters a letter (b,g,o,y) and is given a return statement depending on the letter (char) entered.
Code:
#include <stdio.h>
int main(void)
{
//variables
char answer = 'x';
//input
printf ("Welcome.\n");
printf("Enter the first letter of the cylinder's color: \n");
scanf("%d", &answer);
//output based on the users input
//outcomes depend on the letter entered
switch(answer)
{
case 'b': case 'B': printf("The content is carbon monoxide.\n");
break;
case 'g': case 'G': printf("The content is oxygen.\n");
break;
case 'o': case 'O': printf("The content is ammonia.\n");
break;
case 'y': case 'Y': printf("The content is hydrogen.\n");
break;
default: printf("The content(s) of the cylinder is unknown.\n");
break;
}
//end
printf("Thank you. \n");
return 0;
}
The user is prompted for a letter, and the program takes in to consideration a lower or upper case. If the letter entered does not match any case, an unknown is returned - a match returns it's corresponding statement.
My problem today is that no matter what, it returns the default - unless I change the 'x' to one of the 4 letters. Any hints are appreciated.