<分区>
我正在借助开关运算符制作一个加减乘除程序。在这里,我想制作一个程序,仅当用户输入任何其他字符而不是“Y”时才会停止。问题是:当我运行程序时,在各个案例的结果之后它只打印“你想继续吗”然后程序停止。请帮忙!先感谢您! :)
#include<stdio.h>
int main() {
int n,a,b;
char answer;
while(1) {
printf("enter \n1.Addition \n2.subtraction \n3.division \n4.multiplication\t");
scanf("%d",&n);
switch(n) {
case 1: {
printf("enter value of a and b:\t");
scanf("%d %d",&a,&b);
printf("addition of %d+%d is %d",a,b,a+b);
goto ans;
}
case 2: {
printf("enter the value of a and b:\t");
scanf("%d %d",&a,&b);
printf("Subtraction of %d-%d is %d",a,b,a-b);
goto ans;
}
case 3: {
printf("enter the value of a and b:\t");
scanf("%d %d",&a,&b);
printf("Division of %*% is %d",a,b,a/b);
goto ans;
}
case 4: {
printf("enter the value of a nad b:\t");
scanf("%d %d",&a,&b);
printf("Multiplication of %d*%d is %d",a,b,a*b);
goto ans;
}
default: printf("invalid value!");
goto ans;
}
ans: {
printf("Do you want to continue?(Y/N):\t");
scanf("%c",&answer);
if(answer=='Y') continue;
else break;
}
}
return 0;
}