在C语言中有下题 求怎么写代码

2025-05-08 14:24:00
推荐回答(1个)
回答1:

//希望我的回答对你的学习有帮助
#include 

int main()
{
float OriginalPrice, PresentPrice;
int UseTime;

while (1)
{
printf("Please input the use time and original price:(sample:8 10000)\n");
scanf_s("%d %f", &UseTime, &OriginalPrice);
if (UseTime < 0) break; //输入负数,结束程序

if (UseTime < 3) PresentPrice = OriginalPrice;
else if (UseTime >= 3 && UseTime < 6) PresentPrice = OriginalPrice * 0.02;
else if (UseTime >= 6 && UseTime < 12) PresentPrice = OriginalPrice * 0.05;
else if (UseTime >= 12 && UseTime < 21) PresentPrice = OriginalPrice * 0.08;
else PresentPrice = OriginalPrice * 0.1;

printf("The Depreciation price is : %.2f\n\n", PresentPrice); //保留两位小数点
}

return 0;
}