C在控制台输入代码后不显示代码

标签 c

我目前正在做大学任务,使用 C 创建一个简单的程序,用于输入和显示商店中衬衫的价格。问题是我在控制台输入价格后它不显示价格。我真的不明白问题是什么,因为我在 C 上编码的经验大约有 1 周。有人可以帮忙吗?谢谢。

int main(void)
{
   float small = 0.0; 
   float medium = 0.0; 
   float large = 0.0;
   float total = 0.0;
   printf("Set Shirt Prices\n");
   printf("================\n");
   printf("Enter the price for a SMALL shirt: $");
   scanf("%f", &small);
   printf("Enter the price for a MEDIUM shirt: $");
   scanf("%f", &medium);
   printf("Enter the price for a LARGE shirt: $");
   scanf("%f\n", &large);
   printf("Shirt Store Price List\n");
   printf("======================\n");
   printf("SMALL : $%f\n", small);
   printf("MEDIUM : $%f\n", medium);
   printf("LARGE : $%f\n", large);
   return 0;
}

最佳答案

这一行有问题:

scanf("%f\n", &large);

它期望用户输入一个 float ,然后输入附加文本。 将其更改为:

scanf("%f", &large);

如果想要行尾字符,您可以将其添加到下一条语句之前。

printf("\nShirt Store Price List\n");

关于C在控制台输入代码后不显示代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73751236/

相关文章:

c - 正在使用未初始化变量 UB 的地址吗?

python - 销毁 PyCapsule 对象

c - VLC3编译错误: linking issue with the libavutil library

python - 在 C 和 NumPy 数组中的数据缓冲区之间进行转换,为 Python 接口(interface)包装 C 程序的最佳方法?

c - K&R malloc 代码没有意义?

c - *初学者* C : incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'

c - 在转换为 int ** 后取消引用指针如何更改它指向的值?

c - 用 C 抓取网页的最简单方法是什么?

c - union、.c 和 .h 文件中的 Typedef 嵌套结构

c - 使用系统调用执行c程序