gpt4 book ai didi

c - 同时输入两个变量时如何显示逗号?

转载 作者:行者123 更新时间:2023-11-30 20:20:26 27 4
gpt4 key购买 nike

我被要求提供一个代码寄存器,其输入后面是:

请输入要支付的金额:$8.68所需加元:8,欠余额 0.68 美元所需宿舍:2 个,欠余额 0.18 美元

第一句已完成,但第二句尚未完成,因为地址前的逗号与“余额”一词前的逗号重叠。有没有办法像上面一样显示逗号,并保留地址的逗号?

#include <stdio.h>

int main(void){

int n_loonies;
int n_quarters;
float remaining;
double amount;
amount = 8.68;
n_loonies = amount / 1;
remaining_loonies = amount -(n_loonies * 1);
n_quarters = amount / 0.25;
remaining_quarters = amount - (n_quarters * 25);

printf("Please enter the amount to be paid:$");
scanf("%lf", &amount);
// printf("loonies required: n_loonies");
// scanf("%d", &n_loonies);
printf("Loonies required:%d,n_loonies, balance owing $%d\n);

return 0;
}

最佳答案

看起来你的打印语句有点不对劲。代码看起来无法编译,下面是如何使用 print 的示例:

int x = 10;
printf("x: %d, x address: %p\n", x, (int *)&x);

关于c - 同时输入两个变量时如何显示逗号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46313139/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com