#include<stdio.h>
void main()
{
int date , price, x;
printf("Enter the date returning the books \n");
scanf("%d",&date);
if(date <= 5)
price=50;
printf("The price is %d",price);
else if((date > 5) && (date <= 10))
x=date-5;
price=50+x;
printf("The price is %d \n",price);
else if((date >10) && (date <= 30))
x=date-10;
price=55+5*x;
printf("The price is %d \n",price);
else
printf("You'd lost the member qualification");
}
前面if下面有多条语句,但是没加大括号,后面也一样
#include<stdio.h>
int main()
{
int date , price, x;
printf("Enter the date returning the books \n");
scanf("%d",&date);
if(date <= 5){
price=50;
printf("The price is %d",price);}
else if((date > 5) && (date <= 10)){
x=date-5;
price=50+x;
printf("The price is %d \n",price);}
else if((date >10) && (date <= 30)){
x=date-10;
price=55+5*x;
printf("The price is %d \n",price);}
else
printf("You'd lost the member qualification");
}
如果if else语句后面超过了一行代码,要加大括号括起来哦。
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!