c - 在我的函数数组中没有获得正确的计数器

标签 c arrays function

函数 hot_days(),有两个参数:当前月份的气温数量和存储气温的数组。搜索 temp 数组并计算中午温度超过 32 的所有天数。返回此计数。

检查代码末尾的 hot_days 函数。 icounter 不工作,我认为问题出在 x < 32 上。

#include <stdio.h>
    #include <conio.h>
    #define HIGH 32

    //function prototypes
    void read_temps(int []);

    void hot_days(int [], int []);

    int main()
    {


        //Array
        int TempsAry[31];
        int hotAry[31];

        //sending array 
        read_temps(TempsAry);

        //sending hot array
        hot_days(TempsAry, hotAry);






    getch();
    return 0;
        }

void read_temps(int TempsAry [])
{

      // variables
        int tempnum ;
        int x = 0 ;
        int icount = 0;


        while (x < 31)

    {
        // entering temperature

        printf("Please enter today's temperature:\n ");
        scanf("%d",&tempnum);

        if (tempnum <= -500)
        {
           break;         
        } 

         TempsAry[x] = tempnum;                   
         ++x;
         icount = icount +1;
      }

        //outputting array      
        for (x = 0 ; x<icount; ++x) 
        {
        printf("%d\n",TempsAry[x]);
        }
}

 void hot_days(int TempsAry [], int hotAry [])
 {
    int x = 0 ;
    int icount = 0;

    while (x<31)
    {
          if (TempsAry[x] > HIGH)
          {
            hotAry[x] = TempsAry[x];
            ++icount;              
          }

          ++x;   
    }

    printf("%d\n", icount);  









 }

最佳答案

这段代码没有任何问题,它工作正常。在 ideone 上查看代码片段。

关于c - 在我的函数数组中没有获得正确的计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828642/

相关文章:

java - 重复该程序,直到用户在数组中键入 none

arrays - bash 将数组拆分为具有动态名称的单独文件

excel - VBA - 反转功能

javascript - 将函数返回值保存在 const 中是未定义的

c - 即使声明为(已使用),PROGMEM 变量也会被丢弃

c - 如何在函数中打印 void * 以及如何在函数中访问 void * 变量?

c - 使用与二进制相关的 fread 和 fwrite

javascript - 连接的数组数量超过堆栈允许的数量

javascript - 如何在 Event.observe(n ,"click",respondClick) 之后执行函数

C使用指向结构指针的指针