马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct toupiao
{
char name[20];
int piaoshu;
}a = {"小甲鱼"}, b = {"苍井空"}, c = {"小泽玛利亚"},d = {"松岛枫"} ;
void main()
{
char shuru[20] ;
int i, max, a1=0, b1=0, c1=0, d1=0;
int x[4]={0,0,0,0};
printf("\t\t\t欢迎进入优秀老师投票系统!\n\n\n");
printf("选举候选人:\n\t\t\t小甲鱼,苍井空,小泽玛利亚,松岛枫\n");
printf("********************************************************************************\n\n\n");
for ( i=1 ; i<11 ; i++ )
{
printf("第%d位投票,请输入候选人的名字:",i);
gets( shuru );
if( strcmp(shuru,a.name)==0 )
{
x[0]++;
}
else if( strcmp(shuru,b.name)==0 )
{
x[1]++;
}
else if( strcmp(shuru,c.name )==0 )
{
x[2]++;
}
else if( strcmp(shuru,d.name )==0 )
{
x[3]++;
}
}
max = x[0] ;
for( i=1 ; i<4 ; i++ )
{
if(max < x[i])
{
max = x[i];
}
}
printf("********************************************************************************\n");
printf("\t各候选人的票数如下:\n\t小甲鱼: %d 票\n\t苍井空: %d 票\n\t小泽玛利亚: %d 票\n\t松岛枫: %d 票\n\n", x[0], x[1], x[2],x[3] );
if( max == x[0] )
{
printf("本次投票的胜利者是: %s \n", a.name);
}
else if( max == x[1] )
{
printf("本次投票的胜利者是: %s \n", b.name );
}
else if( max == x[2] )
{
printf("本次投票的胜利者是: %s \n", c.name );
}
else if( max == x[3] )
{
printf("本次投票的胜利者是: %s \n", d.name );
}
system("pause");
}
|