浮点输出不正确

Jal*_*501 1 c math floating-point input output

我创建了一个程序,为用户输入一个输入,然后让他们输入他们想要输入的数量,但是当我打印总数和金额时.然而,这正在全面反转相同的价值:即

总计:5.00食物:5.00票据:5.00旅行:5.00 fags:5.00

代替:

总计:14.00食物:2.00票据:3.00旅行:4.00 fags:5.00

int main(void)
{

float food = 0.00;
float travel = 0.00;
float bills = 0.00;
float fags = 0.00;
float total = 0.00;

float t_food, t_travel, t_bills, t_fags;

char userInput[3];

while(userInput[0] != 'X')
{

    printf("Select option,\nA: Food\nB: Travel\nC: Bills\nD: Fags\nX: Exit\n");
    scanf("%s", userInput);
    if((userInput[0] == 'A') || (userInput[0] =='a'))
    {
        printf("Please enter an amount: ");
        scanf("%f", &food);
        printf("You have entered: %.2f\n", food);
        t_food += food;

    }
    if((userInput[0] == 'B') || (userInput[0] =='b'))
    {
        printf("Please enter an amount: ");
        scanf("%f", &travel);
        printf("You have entered: %.2f\n", travel);
        t_travel += travel;

    }
    if((userInput[0] == 'C') || (userInput[0] =='c'))
    {
        printf("Please enter an amount: ");
        scanf("%f", &bills);
        printf("You have entered: %.2f\n", bills);
        t_bills += bills;

    }
    if((userInput[0] == 'D') || (userInput[0] =='d'))
    {
        printf("Please enter an amount: ");
        scanf("%f", &fags);
        printf("You have entered: %.2f\n", fags);
        t_fags += fags;

    }
    if((userInput[0] =='X') || (userInput[0] =='x'))
    {
        total = t_food + t_fags + t_travel + t_bills;

        printf("Total: %.2f\n", &total);
        printf("Food: %.2f\n", &t_food);
        printf("Travel: %.2f\n", &t_travel);
        printf("Bills: %.2f\n", &t_bills);
        printf("Fags: %.2f\n", &t_fags);
        break;
    }
}
return 0;
Run Code Online (Sandbox Code Playgroud)

}

有任何想法吗?

Bar*_*mar 7

更改

    printf("Total: %.2f\n", &total);
    printf("Food: %.2f\n", &t_food);
    printf("Travel: %.2f\n", &t_travel);
    printf("Bills: %.2f\n", &t_bills);
    printf("Fags: %.2f\n", &t_fags);
Run Code Online (Sandbox Code Playgroud)

    printf("Total: %.2f\n", total);
    printf("Food: %.2f\n", t_food);
    printf("Travel: %.2f\n", t_travel);
    printf("Bills: %.2f\n", t_bills);
    printf("Fags: %.2f\n", t_fags); 
Run Code Online (Sandbox Code Playgroud)

听到编译器说的话,

warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float *’ [-Wformat]
Run Code Online (Sandbox Code Playgroud)