所以基本上,我的C代码输出应该是这样的。
但是我相信我的IF语句是不正确的,有人能看一下并给我一些提示吗?

#include <stdio.h>

int main()
{
    int a, total = 0; // Defining integers
    int n;
    int tax;
    int e;

    float subtotal;

    printf("Enter the number of days the car was rented: "); // Asking for input
    scanf("%d", &n); // Establishing number of cars

    printf("Enter the number of miles the car was driven: "); // Mile input
    scanf("%d", &a); // Establishing miles driven

    if (n > 200) {
        e = .40;
    }
    else { e = .35;
    }

    subtotal = n * 15 + a * e;

    printf("\nSubtotal: ", subtotal);

}

最佳答案

您定义的e变量是一个int变量,而不是浮点类型,如floatdouble,并且您忘记在上一个print语句中添加"%f"
要添加更多指针:
变量应该被赋予有意义的名称。我敢肯定,如果您将变量名e改为precentage,上面的int/float问题可能不会发生。
应删除所有未使用的变量(totaltax)。

关于c - 我的C代码有什么问题?有指针吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40252563/

10-11 23:04
查看更多