投票

#include <stdio.h>
#include <string.h>

//设计表决算法

//有5个人投票,当有3个或以上的人同意时,投票通过。
int main()
{
  char voter[]={'A','B','C','D','E'};    //5个选举人                         
  int agreeCount=0    ;                   //同意的票数
  printf("please input 'Y' means agreed,'N' means disagreed:\n");
  for(int i=0;i<sizeof(voter)/sizeof(char);i++)
  {          
       printf("%c >",voter[i]);
      char buf[16];
      gets(buf);
          if(buf[0]=='Y' ||buf[0]=='y')                //如果投票为'Y',则计数加1
              agreeCount++;     
  }
  printf("total agree count is %d \n",agreeCount);
  if(agreeCount>=3)
      printf("Vote Result is PASS !\n");

  return 0;
 }

 

posted @ 2016-01-12 20:56  爱蜗牛的神牛  阅读(177)  评论(0编辑  收藏  举报