倒数第七行的 else 该怎样用,,才能无误运行出来。。
#include "stdio.h"#include "string.h"
void main()
{
int hao,a,b,c,d,max;
char name[10];
printf("候选人如下:\n");
printf("1、张三\n2、李四\n3、王五\n4、赵六\n");
a=b=c=d=0;
hao = -1;
for(;hao != 0;)
{
printf("请输入候选人的代号,按0结束:");
scanf("%d",&hao);
switch(hao)
{
case 1: a++;break;
case 2: b++;break;
case 3: c++;break;
case 4: d++;break;
case 0: break;
default : printf("此票无效!\n");
}
}
printf("投票结果如下:\n");
printf("张三:%d票\n",a);
printf("李四:%d票\n",b);
printf("王五:%d票\n",c);
printf("赵六:%d票\n",d);
if(a>b)
max = a; strcpy(name,"张三");
else
max = b; strcpy(name,"李四");
if(c>max)
max = c; strcpy(name,"王五");
if(d>max)
max = d; strcpy(name,"赵六");
printf("恭喜%s被当选为班长\n",name);
}