C语言编程题目:查询水果的单价 有4 种水果,苹果(apple)梨(pear)橘子(orange)和葡萄(grape),单价
发布网友
发布时间:2022-04-26 22:44
我来回答
共5个回答
热心网友
时间:2023-11-11 01:05
#include<stdio.h>
int main(void){
int i,x,n;
float a=3.0,p=2.5,o=4.1,g=10.2;
printf("Enter choice: ");
scanf("%d",&x);
for(i=1;;i++){
switch(x)
{case 0:break;
case 1:
printf("price=%.1f\n",a);
printf("Enter choice:");
scanf("%d",&x);
break;
case 2:
printf("price=%.1f\n",p);
printf("Enter choice: ");
scanf("%d",&x);
break;
case 3:
printf("price=%.1f\n",o);
printf("Enter choice: ");
scanf("%d",&x);
break;
case 4:
printf("price=%.1f\n",g);
printf("Enter choice: ");
scanf("%d",&x);
break;
default:
printf("price=0\n");
printf("Enter choice: ");
scanf("%d",&x);}
n++;
if(n==6){
printf("Thank you!");
break;}
}
return 0;
}
热心网友
时间:2023-11-11 01:06
#include<stdio.h>
int main(void)
{
int choice,i;
double price;
printf("[1] apple\n");
printf("[2] pear\n");
printf("[3] orange\n");
printf("[4] grape\n");
printf("[0] exit\n");
for(i=1;i<=5;i++){
scanf("%d",&choice);
if(choice==0)
break;
switch(choice){
case 1:price=3.00;break;
case 2:price=2.50;break;
case 3:price=4.10;break;
case 4:price=10.20;break;
default:price=0.00;break;
}
printf("price = %.2f\n",price);
}
return 0;
}
热心网友
时间:2023-11-11 01:06
控制台么?
热心网友
时间:2023-11-11 01:07
你想表达什么呀
热心网友
时间:2023-11-11 01:06
#include<stdio.h>
int main(void){
int i,x,n;
float a=3.0,p=2.5,o=4.1,g=10.2;
printf("Enter choice: ");
scanf("%d",&x);
for(i=1;;i++){
switch(x)
{case 0:break;
case 1:
printf("price=%.1f\n",a);
printf("Enter choice:");
scanf("%d",&x);
break;
case 2:
printf("price=%.1f\n",p);
printf("Enter choice: ");
scanf("%d",&x);
break;
case 3:
printf("price=%.1f\n",o);
printf("Enter choice: ");
scanf("%d",&x);
break;
case 4:
printf("price=%.1f\n",g);
printf("Enter choice: ");
scanf("%d",&x);
break;
default:
printf("price=0\n");
printf("Enter choice: ");
scanf("%d",&x);}
n++;
if(n==6){
printf("Thank you!");
break;}
}
return 0;
}
热心网友
时间:2023-11-11 01:08
控制台?
热心网友
时间:2023-11-11 01:06
#include<stdio.h>
int main(void)
{
int choice,i;
double price;
printf("[1] apple\n");
printf("[2] pear\n");
printf("[3] orange\n");
printf("[4] grape\n");
printf("[0] exit\n");
for(i=1;i<=5;i++){
scanf("%d",&choice);
if(choice==0)
break;
switch(choice){
case 1:price=3.00;break;
case 2:price=2.50;break;
case 3:price=4.10;break;
case 4:price=10.20;break;
default:price=0.00;break;
}
printf("price = %.2f\n",price);
}
return 0;
}
热心网友
时间:2023-11-11 01:06
控制台么?
热心网友
时间:2023-11-11 01:07
你想表达什么呀
热心网友
时间:2023-11-11 01:08
控制台?