void main()
{
printf(" IT Magey \n");
int code;
printf("\nEnter item code : T");
scanf("%d", &code);
double price;
printf("Enter item price : ");
scanf("%lf", &price);
double dct;
printf("Enter discount ('%%') : ");
scanf("%lf", &dct );
char m;
printf("Enter payment mode (F or I): ");
scanf("%c \n", &m);
switch (m)
{
case 'F':
case 'f':
printf("\n");
printf("Payment Details \n");
printf("-----------------------------\n");
printf("Item Code : T003256\n");
printf("Item price: USD 2342.80\n");
double dct1=price*dct/100;
printf( "Discount: USD%lf \n", dct1);
double amount1=price-dct1;
printf("Amount to pay: USD%lf", amount1 );
break;
case 'I':
case 'i':
printf("\n");
int mth;
printf("Enter number of installments (months) : ");
scanf("%d", &mth);
printf("\n");
printf("Payment Details \n");
printf("-----------------------------\n");
printf("Item Code : T003256\n");
printf("Item price: USD 2342.80\n");
double dct2=price*dct/100;
printf( "Discount: USD%lf \n", dct2);
double amount2=price-dct1;
printf("Amount to pay: USD%lf", amount2 );
printf("\n");
printf("Number of installments : %d \n", mth);
double amount3=price/mth;
printf(" Amount to pay per installement : USD%lf", amount3 );
break;
default:
printf("Please select only F or I");
}
新手,我的 switch 语句除了默认输出之外不会显示任何输出。尽管如此,我已经添加(中断)到它仍然相同。如果除了 switch 语句之外,该程序还有其他问题,也请一并列出。谢谢:)
刚开始使用这个网站,我正在尝试填写更多细节以满足细节太少的错误:/
编辑#1:因此在将switch ('m')更改为switch(m) 后,我的输出仍然相同。如果我尝试使用 if..else if,我希望我的输出只显示“F”或“f”代码,我得到的是包含“I”和“i”代码的所有内容。
switch 语句中传入的参数是字符常量 'm'
,而不是m
要检查的变量。
你必须像这样通过:
switch (m) {
//your code goes here
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句