候选人投票
#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;
}