/设计一个投票系统
#include <stdio.h>
#include <string.h>
struct houxuan{
char *name;
int piaoshu;
} ;
void main(){
printf("您已经进入投票系统:\n");
printf("候选人如下:\n"
"liming\n"
"hanmeimei\n"
"lihue\n"
"lili\n"
);
struct houxuan ren[4]={{"liming",0},{"hanmeimei",0},
{"liahua",0},{"lili"},0};
char result[100]="lili";
for(int i=1;i<11;i++){
printf("您是第%d位投票者,请输入您选择的人名:",i);
scanf("%s",&result);
if(strcmp(result,"liming")==0){
ren[0].piaoshu++;
}if(strcmp(result,"hanmeimei")==0){
ren[1].piaoshu++;
}if(strcmp(result,"liahua")==0){
ren[2].piaoshu++;
}if(strcmp(result,"lili")==0){
ren[3].piaoshu++;
}
}
printf("************ plese wait ***********\n\n\n\n");
int max=0;
for (int i=0;i<4;i++) {
if(ren[i].piaoshu>max){
max=i;
}
printf("%s票数是%d\n", ren[i].name, ren[i].piaoshu);
}
printf("获选的是:%s,其所得的票数为:%d",ren[max].name,ren[max].piaoshu);
}
|