Green1111 发表于 2014-3-19 03:52:36

小甲鱼视频投票系统题

#include <stdio.h>
#include <string.h>
struct ren
{
        char name;
    int count;
};
struct ren person={"张三",0,"李四",0,"燕小六",0};
void main()
{
        printf("************************************\n投票选出今年的国家形象大使\n************************************\n");
    printf("候选人有:张三,李四,燕小六\n请准确输入姓名,否则影响投票结果\n\n\n\n");
    //定义数据
    char n={0};
    struct ren *p=person;
    int i=0,j=0;
    int max=0;
    int index=0;

    //输入数据

    for(i=0;i<7;i++)
    {
                printf("请输入第%d票:",i+1);
      scanf("%s",n);

      for(j=0;j<3;j++)
      {
                        if(strcmp(n,(p+j)->name)==0)
            {
                                (p+j)->count++;
            }
      }
    }
   printf("---------------------------------------------------------\n\n");
    printf("%s的得到的票数是:%d\n",person.name,person.count);
    printf("%s的得到的票数是:%d\n",person.name,person.count);
    printf("%s的得到的票数是:%d\n\n",person.name,person.count);
    printf("---------------------------------------------------------\n");
    //统计得票最多的
       
    max=p->count;
    for(i=0;i<3;i++)
    {
       
      if(((p+i)->count)>max)
      {
      max=(p+i)->count;
      index=i;
      }

    }

   if(max==person.count && person.count==person.count || person.count==person.count)
    //这样存在一个错误,当person.count最大,person.count与person.count相同时,条件会成立,结果错误。因为&&优先级比||的优先级高,会让前两者结合成一个条件,然后第三个自己是个条件。
    {printf("最高得票有相同,需要改日再选"); system("pause"); exit(0);}
    if(max==person.count && person.count==person.count)
    {printf("最高得票有相同,需要改日再选"); system("pause"); exit(0);}
    if(max==person.count && person.count==person.count)
    {printf("最高得票有相同,需要改日再选"); system("pause"); exit(0);}

    //输出结果

    printf("恭喜%s获选!\n",(p+index)->name);


    system("pause");

}

页: [1]
查看完整版本: 小甲鱼视频投票系统题