Election方法1

 

方法1:


//    工程名:Election
//    文件名:Election.cpp
//    功能:统计候选人的投票数
//    依赖文件:无

#include 
<iostream>
#include 
<string> 
using namespace std;

const int n=3;    //假设有3个候选人
struct Person
{
    
string name;
    
int count;
}
Leader[n];

void Election(Person Leader[],int n)
{
    
string name;
    cout
<<"请输入候选人名为其投票:";
    cin
>>name;
    
while(name!="#")
    
{
        
for(int i=0;i<n;i++)
        
if(Leader[i].name==name)Leader[i].count++;
        cout
<<"继续投票以“#”结束输入:";
        cin
>>name;
    }

    
for(int i=0;i<n;i++)
    cout
<<Leader[i].name<<"得票数为,"<<Leader[i].count<<endl;
}


void main()
{
    
for(int i=0;i<n;i++)
    
{
        cout
<<"请输入第i个候选人名字(共3个):"<<endl;    //这个功能有欠缺
        string name;
        cin
>>name;
        Leader[i].name
=name;
    }

    Election(Leader,n);
}

 

posted @ 2007-06-23 19:37  生活不是用来挥霍的  阅读(258)  评论(0)    收藏  举报