| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 358 人关注过本帖
标题:数组的问题
只看楼主 加入收藏
大笑的蚂蚁
Rank: 1
等 级:新手上路
帖 子:12
专家分:5
注 册:2012-6-9
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:2 
数组的问题
// Storing, displaying and averaging a series of humidity readings, using a two-dimensional array.

#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

int main() {
  const string days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
  const string times[] = {"morning", "midday", "evening"};

  float humidity[sizeof days/sizeof days[0]][sizeof times/sizeof times[0]] = {0.0f};
  float day_averages[sizeof days/sizeof days[0]] = {0.0f};
  float week_averages[sizeof times/sizeof times[0]] = {0.0f};

  // Loops used for entering humidity data and accumulating totals.
  for(int day = 0 ; day < sizeof days/sizeof days[0] ; day++) {
    cout << endl << days[day] << endl;
    for(int time = 0 ; time < sizeof times/sizeof times[0] ; time++) {
      cout << "  Enter " << times[time] << " reading: ";
      cin  >> humidity[day][time];
      week_averages[time] += humidity[day][time];     // Accumulate total for current time
      day_averages[day] += humidity[day][time];       // Accumulate total for current day
    }
  }
  cout << endl;

  // Output average for each day
  for(int day = 0 ; day < sizeof days/sizeof days[0] ; day++)
    cout << "Average humidity for " << days[day]  << ": "
         << day_averages[day]/(sizeof times/sizeof times[0]) << endl;

  cout << endl;

  // Output weekly average for each time
  for(int time = 0 ; time < sizeof times/sizeof times[0] ; time++)
    cout << "Average " << times[time]  << " humidity: "
         << week_averages[time]/(sizeof days/sizeof days[0]) << endl;


  return 0;
}
谁能给解释一下整个过程呢,然后想知道为什么这个程序中途编译时不能正常运行呢???
搜索更多相关主题的帖子: displaying evening include morning 
2012-07-28 23:18
大笑的蚂蚁
Rank: 1
等 级:新手上路
帖 子:12
专家分:5
注 册:2012-6-9
收藏
得分:0 
大家给看一下,哪里出错了啊!!!!
2012-07-30 00:46
liudw2
Rank: 4
等 级:业余侠客
帖 子:85
专家分:248
注 册:2011-7-31
收藏
得分:20 
day重复定义了
main.cpp(26) : error C2374: 'day' : redefinition; multiple initialization
        F:\C源文件\vol\list\main.cpp(14) : see declaration of 'day'
2012-07-30 03:38
快速回复:数组的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016448 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved