我对被跳过的scanf语句有一些问题,但我读到它倾向于吃掉前一个,\n等等. 现在我已经让我的char实际通过了if语句,它只返回我的ELSE,即使我可以保证if语句获得了一个正确的值.
你们看到我的代码可能在哪里出错了吗?
我没有包括我的头文件或任何东西,因为它是一个相当大的代码块,但它到目前为止运行得很好.
char oakAns;
printf("Would you like the sign made out of oak?\n");
printf("Enter y for yes or n for no: ");
scanf(" %c",&oakAns);
printf("%c",oakAns); //this is what i was using to confirm my oakAns input
if((oakAns == 'y')||(oakAns == 'Y')){ // if y then add 15
cost += 15;
}
if((oakAns == 'n')||(oakAns == 'N')){ // but if n then remain same
cost = 30;
}
else { // anything else returns false
printf("Could not compute cost...\n");
return false;
}