This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15817|Reply: 0

[C] Struct array has 3 candidates, and each voter can only vote for one person. Write a statistical vote and output everyone's votes

[Copy link]
Posted on 12/17/2015 4:28:03 PM | | |
There are 3 candidates, each voter can only vote for one person, and it is required to compile a program to count votes, enter the names of the candidates, and finally output the results of each person's votes

#include "stdafx.h"
#include "string.h"
struct Person
{char name[20];
int count;
}leader[3]={"Li",0,"Zhang",0,"Sun",0};

int main(int argc, char* argv[])
{int i,j;
char leader_name[20];
for(i=1; i<=10; i++)
{scanf("%s",leader_name);
    for(j=0; j<3; j++)
    if(strcmp(leader_name,leader[j].name==0)leader[j].count++;
    )
}
    printf("\nResult:\n");
    for(i=0; i<3; i++)
        printf("%5s:d\n",leader[i],name_leader[i].count);
    return 0;
}






Previous:Structure Enter the student number, name, and grade of the two students. Output student number, name, and grades of the highest graded student.
Next:Is it better to install wordpress under linux with apache or nginx?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com