This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
这是我第一次来,我在编写程序时遇到问题。我正在尝试退还月薪和薪水,并根据薪水和汽车付款的大小使用不同的打印报表。但是,我的输出未正确输出。我收到一个.2f作为输出变量,而不是我想要的变量。有谁知道可能出什么问题了?

#include <stdio.h>
#include <math.h>



int main() {
    float cost;
    float interest;
    int years;
    float salary;
    float sal_twenty;
    float payment;
    float IM;
    float NumMon;

    printf("Enter annual income > ");
    scanf("%f", &salary);

    printf("Enter cost of car > ");
    scanf("%f", &cost);

    printf("Enter annual interest rate > ");
    scanf("%f", &interest);

    printf("Enter duration of loan in years > ");
    scanf("%d", &years);

    sal_twenty = salary * .2;
    IM = interest/12;
    NumMon=years*12;
    payment = cost * (IM * pow((IM + 1), NumMon))/(pow((IM + 1), NumMon) - 1);

    if (payment*12 > sal_twenty) {
        printf("A monthly payment of ");
        printf(".2f", payment);
        printf(" is too high given your annual income of ");
        printf(".2f", &salary);
    }

    if (payment*12 <= sal_twenty) {
        printf("Your annual income of ");
        printf(".2f", salary);
        printf(" allows a monthly payment of ");
        printf(".2f", payment);
    }

    return 0;
}

最佳答案

您忘记了%格式的printf。即

printf("%.2f", payment);


等等。 (正如您对scanf所做的正确操作一样)

关于c - C中的每月付款,带有变量和输出的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16112547/

10-11 23:01
查看更多