c - 如何计算输入的数字?
问题描述
程序应该运行的方式是计算用户输入和输出该组中有多少个数字。
#include <stdio.h>
int main () {
int input;
int sum = 0;
int count = 0;
int hiprc, avgprc, loprc;
int avg;
while (input != -99)
{
printf("Enter the price (-99 to stop): ");
scanf("%d", &input);
sum = sum + input;
count++;
}
if (hiprc = input >= 85)
printf("Number of high prices is \n", hiprc);
if (avgprc = hiprc < input && input > loprc)
printf ("Number of average prices is \n", avgprc);
if (loprc = input >= 60)
printf ("Number of low prices is \n", loprc);
avg = sum/count;
printf("Average Price is %.2f\n", avg);
return 0;
}
当我运行它时,它显示最高价格,添加平均价格,并为低价输出 0。它应该输出高、平均和低的数字。
High prices: 4
Average Prices: 15
Low Prices: 3
The average price is: xx.xx
这是用一些评论建议编辑的
解决方案
if(hiprc < input > loprc)
与数学中的含义不同。
改为使用if(hiprc < input && input > loprc)
。
推荐阅读
- assembly - arm32 asm -- fp 未设置为旧 sp
- android - 暂存应用程序.... 解析包时出现问题
- html - 下拉菜单内容与其菜单项重叠
- jupyter-notebook - Jupyter Notebooks nbextension varInspector 拖出浏览器,现在我找不到/看到它
- dart - 找不到名为“devtools”的命令
- rancher - Rancher 和容器之间的连接是如何建立的?
- php - 更改摘要报告以按字母顺序排序
- google-cloud-platform - 谷歌云存储授权
- xamarin - 我在两个平台代码上都使用 Xamarin Form 5.0 Clearing Cookies 不起作用
- excel - 使用 PowerShell 访问 Excel