所以我正在学习如何在C语言中使用while和for循环,但是这段代码似乎无法正常工作。 scanf语句似乎被忽略了,循环只是重复自身而无需我输入'Y'使其重复。这是代码:
void showCommission();
void main(){
char keepGoing='y';
while(keepGoing=='y'){
showCommission();
printf("Do you want to calculate another?\n");
scanf("%c",&keepGoing);}}
void showCommission(){
float sales,commission;
const float COM_RATE=0.10;
printf("Enter the amount of sales\n");
scanf("%f",&sales);
commission=sales*COM_RATE;
printf("The commission is $%f.\n",commission);}
while(keepGoing =='y'),'y'输入区分大小写。比较之前,请尝试将输入转换为小写或大写。或者,您可以尝试使用while(keepGoing =='y'|| keepGoing =='Y')
比较