视频 例题 希望鱼友帮助啊
#include <stdio.h>#include <string.h>
#include <stdlib.h>
#define NUM 4
struct person
{
char name;
int count;
}candidate={
{"小甲鱼",0},
{"小黄鱼",0},
{"小黑鱼",0},
{"小大雨",0}
};
char *winner();
void main()
{
int i,j;
char candidate_name;
printf("欢迎进入良好公民投票系统:()\n\n");
printf("候选人有:小甲鱼,小黄鱼,小黑鱼,小大雨\n\n");
for(i=1;i<=10;i++)
{
printf("第%d位投票,请写下支持的候选人名字:",i);
scanf("%s",candidate_name);
for(j=0;j<NUM;j++)
{
if(0==strcmp(candidate_name,candidate.name))
{
candidate.count++;
}
}
}
printf("\n");
for(i=0;i<4;i++)
{
printf("%s同学得票为:%d\n",candidate.name,candidate.count);
}
printf("\n");
printf("本次投票活动的胜利者:%s",winner());
printf("\n");
system("pause");
}
char *winner()
{
int i,winner=i;
for(i=0;i<NUM;i++)
{
if(candidate.count<candidate.count)
{
winner=i;
}
}
return (candidate.name);
}
char *winner()
{
int i=0, winner = i;
for (i = 0; i < NUM; i++)
{
if (candidate.count < candidate.count)
{
winner = i;
}
}
return (candidate.name);
}
记得初始化下 谢谢喽
{:1_1:}
页:
[1]