投票系统
#include<stdio.h>#include <string.h>
#define J 5
#define T 10
int t,i = 0;
int max = 0;
char tp={"0"};
struct{
char name;
int count;
}man = {{"小甲鱼", 0}, {"小海豚", 0}, {"小乌龟", 0}, {"小丁丁", 0},{"无效", 0}};
int main(void){
printf("欢迎来到友好公民投票系统:\n\n候选人有:“小甲鱼”“小海豚”“小乌龟”“小丁丁”\n\n");
while(i < 10){
printf("第 %d 位投票者:",i+1);i++;
scanf("%s",&tp);
int count = 0;
for(int j = 0;j < J-1;j++){
if(strcmp(man.name,tp) == 0)
man.count++;
else{
count++;
if(count == 4){
man.count++;
}
}
}
}
for(i = 0;i < J;i++)
printf("\t%s 的票数:%d\n",man.name,man.count);
for(i = 0;i < J-1;i++){
if(max < man.count){
max = man.count;
t = i;
}
}
if(man.count == 10)
printf("本次没有胜利者!\n");
else
printf("\n得票最多的是: %s",man.name);
return 0;
}
页:
[1]