printf("请选择加油方式:s或a或n(s自助,a协助,n普通):\n")
service = getchar()
移动到最前面输入,这样应该就可以解决你的问题了
#include <stdio.h>#include <stdlib.h>
int main()
{
int weight
float price1,price2,price3,result
int choose
int flag
price1 = 1.5
price2 = 1.35
price3 = 1.12
printf("请输入加油量:")
scanf("%d",&weight)
printf("请选择汽油型号(90选择1,93选择2,97选择3):")
scanf("%d",&choose)
switch(choose){
case 1: result = price1 * weightbreak
case 2: result = price2 * weightbreak
case 3: result = price3 * weightbreak
default: printf("输入错误")break
}
printf("请选择服务类型(自助服务选择1,非自助服务选择2):")
scanf("%d",&flag)
if(flag == 1){
result = result * (1-0.1)
}else if(flag == 2){
result = result * (1-0.05)
}else{
printf("输入错误")
}
printf("本次消费:%.2f",result)
}
#include<stdio.h>#include<string.h>
#include<stdlib.h>
int main()
{
int N,K,m,i,t,a[20]={0}
scanf("%d %d",&N,&K)
for(i=0i<K+1i++)
{
scanf("%d",&a[i])
}
m=N
m=m-a[0]
i=1
t=0
while(1)
{
if(m<0){printf("No Solution")break}
if(m-a[i]<0){t++m=N-a[i]}
else m=m-a[i]
i++
if(m<0){printf("No Solution\n")break}
if(i==K+1){printf("%d\n",t)break}
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)