码迷,mamicode.com
首页 > 其他好文 > 详细

候选人投票

时间:2015-04-14 00:13:12      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define NUM_ELECTORATE 10
#define NUM_CANDIDATE 3
struct candicate
{
 char name[20];
 int count;
}candidate[3] = {"li",0,"zhang",0,"wang",0};
int main()
{
 int i,j,flag = 1, wrong = 0;
 char name[20];
 for(i = 1;i <= NUM_ELECTORATE;i++)
 {
  printf_s("input vote %d :",i);
  scanf_s("%s",name,sizeof(name));
  _strlwr_s(name);
  flag = 1;
  for(j = 0;j < NUM_CANDIDATE;j++)
  {
   if(strcmp(name,candidate[j].name) == 0)
   {
    candidate[j].count++;
    flag = 0;
   }
  }
  if(flag)
  {
   wrong++;
   flag = 0;
  }
 }
 printf_s("Election results:\n");
 for(i = 0;i < NUM_CANDIDATE;i++)
 {
  printf_s("%8s:%d\n",candidate[i].name,candidate[i].count);
 }
 printf_s("Wrong election:%d\n",wrong);
 system("pause");
 return 0;
}

候选人投票

标签:

原文地址:http://www.cnblogs.com/joyclub/p/4423500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!