| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3495 人关注过本帖
标题:switch case 问题!!
取消只看楼主 加入收藏
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
 问题点数:0 回复次数:5 
switch case 问题!!

switch(sum) { case 0: int Z[7]={0,0,0,0,0,0,0}; break; case 1: int Z[7]={0,0,0,0,0,0,1}; break; case 2: int Z[7]={0,0,1,0,0,0,0}; break; case 3: int Z[7]={0,0,0,1,0,0,0}; break; }

问题 显示 :

作业.cpp E:\程序\作业.cpp(34) : error C2360: initialization of 'Z' is skipped by 'case' label E:\程序\作业.cpp(32) : see declaration of 'Z' E:\程序\作业.cpp(42) : error C2360: initialization of 'Z' is skipped by 'case' label E:\程序\作业.cpp(32) : see declaration of 'Z' E:\程序\作业.cpp(50) : error C2360: initialization of 'Z' is skipped by 'case' label E:\程序\作业.cpp(32) : see declaration of 'Z' E:\程序\作业.cpp(51) : error C2374: 'Z' : redefinition; multiple initialization E:\程序\作业.cpp(32) : see declaration of 'Z' Error executing cl.exe.

不知道 是什么原因啊???

[此贴子已经被作者于2004-10-06 23:37:32编辑过]

搜索更多相关主题的帖子: case switch cpp int break 
2004-10-06 23:29
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

int Z[7]={0}; switch(sum) { //case 0: // int Z[7]={0,0,0,0,0,0,0}; // break; case 1: if(Y[0]==1) Z[4]={1}; if(Y[1]==1) Z[5]={1}; else Z[6]={1}; break; case 2: if(Y[0]==0) Z[0]={1}; if(Y[1]==0) Z[1]={1}; else Z[2]={1}; break; case 3: Z[3]={1}; break; }

显示 如下!!!

作业.cpp E:\程序\作业.cpp(37) : error C2059: syntax error : '{' E:\程序\作业.cpp(37) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(37) : error C2143: syntax error : missing ';' before '}' E:\程序\作业.cpp(39) : error C2059: syntax error : '{' E:\程序\作业.cpp(39) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(39) : error C2143: syntax error : missing ';' before '}' E:\程序\作业.cpp(40) : error C2181: illegal else without matching if E:\程序\作业.cpp(41) : error C2059: syntax error : '{' E:\程序\作业.cpp(41) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(41) : error C2143: syntax error : missing ';' before '}' E:\程序\作业.cpp(45) : error C2059: syntax error : '{' E:\程序\作业.cpp(45) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(45) : error C2143: syntax error : missing ';' before '}' E:\程序\作业.cpp(47) : error C2059: syntax error : '{' E:\程序\作业.cpp(47) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(47) : error C2143: syntax error : missing ';' before '}' E:\程序\作业.cpp(48) : error C2181: illegal else without matching if E:\程序\作业.cpp(49) : error C2059: syntax error : '{' E:\程序\作业.cpp(49) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(49) : error C2143: syntax error : missing ';' before '}' E:\程序\作业.cpp(52) : error C2059: syntax error : '{' E:\程序\作业.cpp(52) : error C2143: syntax error : missing ';' before '{' E:\程序\作业.cpp(52) : error C2143: syntax error : missing ';' before '}' Error executing cl.exe.


2004-10-06 23:55
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 
#include<iostream.h>
int main()
{
 int H[3][7]={{0,1,1,1,1,0,0},{1,0,1,1,0,1,0},{1,1,0,1,0,0,1}};
    int X[7];
 cout<<"press enter the Hamming code:";
 cin>>X[0]>>X[1]>>X[2]>>X[3]>>X[4]>>X[5]>>X[6];
 int y[3];
 int Y[3];
 int sum;
 int i,j;
 
 int z[7];
 int S[7];
 for( i=0;i<3;i++)
 {
  sum=0;
  for(j=0;j<7;j++)
 {
  sum=sum+H[i][j]*X[j];
 }
 y[i]=sum;
 }
 for( i=0;i<3;i++)
 {
  Y[i]=y[i]%2;
 }
     sum=Y[0]+Y[1]+Y[2];
  int Z[7]={0};
 switch(sum)
 {
 case 0:
      
  break;
 case 1:
  if(Y[0]==1)
   Z[4]={1};
  if(Y[1]==1)
   Z[5]={1};
  if(Y[2]==1)
   Z[6]={1};
  break;
 case 2:
  if(Y[0]==0)
  Z[0]={1};
  if(Y[1]==0)
   Z[1]={1};
  if(Y[2]==0)
   Z[2]={1};
  break;
 case 3:
      Z[3]={1};
  break;
 }
 for(i=0;i<7;i++)
 {
  z[i]=X[i]+Z[i];
 }
 for(i=0;i<7;i++)
 {
  S[i]=z[i]%2;
 }
 for(i=0;i<7;i++)
  cout<<S[i];
 return 0;
}

2004-10-07 00:05
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 
是一个    编码 的 题目!!

2004-10-07 00:05
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

厉害!!谢谢 了!!

但是我不懂 我刚才 是哪里错了??


2004-10-07 00:29
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

哈哈!!我比猪还笨!! Z[4]=1 我改成了Z[4]={1}

难怪 被 live41 笑!!

[此贴子已经被作者于2004-10-07 00:41:26编辑过]


2004-10-07 00:37
快速回复:switch case 问题!!
数据加载中...
 
   



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

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