【发布时间】:2019-09-28 21:23:22
【问题描述】:
我正在尝试为某个数字加税,但在编译后,该税不包含在该数字的加法中。
我也尝试过 int 或 float 这个 %f 但编译后似乎没有进行数学运算。
#include <stdio.h>
int main()
{
float setprice, price, tax;
printf("enter price in dollars : \n");
scanf("%f", &price);
printf("Enter the tax: \n");
scanf("%f", &tax);
setprice=(price*tax)+price;
printf("total = %f\n", price);
return 0;
}
在 IDE 上输入代码后,这是输出。
输入美元价格: 100 输入税金: 50 总计 = 100.000000
【问题讨论】:
-
欢迎来到 Stackoverflow。我不知道 C#,但这看起来确实像 C 或 C++。请相应地使用正确的标签。
-
我也将关闭标记为错字,因为你写了
printf("total = %f\n", price);,你可能指的是printf("total = %f\n", setprice);。 -
@uneven_mark 嘿,谢谢伙计,我能够解决这个问题。所以我所做的只是修改 setprice=(price+tax); printf("总计 = %f\n", setprice); .现在我能够计算税收和数量,并且输出没有错误。谢谢你,我一定会分配正确的标签。
-
我不知道 C# 中的 printf() 函数。这是 C 还是 C++?
-
printf("total = %f\n", price);而不是printf("total = %f\n", setprice);是那些 ...doah.... 时刻之一——我们都去过那里。 How to debug small programs 帮助。
标签: c