问题:重量小于一大于零时统一为10块钱,重量大于1时,砍去一开始的一公斤。每公斤6块钱,有小数的取整进一。编译可以通过但是输数字的环节出了问题,跳出来为乱码啥的。
代码:
#include
int main(void)
{
/Begin/
int weight1,a;
float weight;
scanf("%f",weight);
if(weight<=1 && weight>0)
a=10;
printf("Price: %.2f",a);
if(weight>1)
weight1=(int)weight;
a=weight1*10+10;
printf("Price: %.2f",a);
/*********End**********/
}#include
int main(void)
{
/*********Begin*********/
int weight1,a;
float weight;
scanf("%f",weight);
if(weight<=1 && weight>0)
a=10;
printf("Price: %.2f",a);
if(weight>1)
weight1=(int)weight;
a=weight1*6+10;
printf("Price: %.2f",a);
/*********End**********/
}
/**问题:重量小于一大于零时统一为10块钱,重量大于1时,砍去一开始的一公斤。
* 每公斤6块钱,有小数的取整进一*/
#include<stdio.h>
int main(){
/*********Begin*********/
int weight1=0;
float weight,a;
printf("请输入重量:\n");
scanf("%f",&weight);
if(weight<=1 && weight>0)
{
a=10;
printf("Price: %.2f",a);
}
else
{
weight1=weight/1;
a=weight1*6+10;
printf("Price: %.2f",a);
}
/*********End**********/
}
scanf("%f",weight);
改为
scanf("%f",&weight);
#include<stdio.h>
int main(void)
{
int weight1;
float weight,a;
scanf("%f",&weight);
if(weight<=1 && weight>0)
{
a=10;
printf("Price: %.2f",a);
}
else if(weight > 1)
{
weight1=(int)weight;
if(weight - weight1 > 0)
weight1++;
a=10 + (weight1-1)*6;
printf("Price: %.2f",a);
}
}