C++中投票问题遇到的困难,大侠们帮忙啊
题目要求:投票管理需求预先指定若干名侯选人(最多12人)
预先指定当选标准(给定百分数)
提供投票功能(不可以选非侯选人)
支持选举结果的输出(当选人和票数)
下面是我写的程序:
demo.h
struct Candidate
{
char name;//候选人名字
int amount;//所得的票数
};
class Demo
{
public:
Candidate can[3];
public:
void demo();
int Iseffvote(char s,Candidate *x);
int Result();
};
demo.cpp
#include<iostream.h>
#include <stdio.h>
#include "demo.h"
void demo()
{
Candidate can[3]={{'a',0},{'b',0},{'c',0}};
}
int Iseffvote(char s,Candidate *x)//*判断输入的候选人是否在指定的当中,是的话相应的票数增加*//
{ Demo d=new demo();
*x=d.can[0];
int flag=0;
for(int i=0;i<3;i++)
{
if(s==d.can[i].name) {d.can[i].amount++;flag=1;}
}
if(flag==0)
cout<< "Input wrong!Please vote one of the candidate again!" <<endl;
return 0;
}
int Result()//*得出结果 如何将上面已经进行加操作的各个的票数带进来,进行下一步的操作???
{ Demo d;
int flag=0;
int n;double m[3];
for(int i=0;i<3;i++)
n+=d.can[i].amount;
for(int j=0;j<3;j++)
m[j]=d.can[j].amount/n;
for(int r=0;r<3;r++)
{
if(m[r]>0.5)
{
cout <<"The winner is" <<d.can[r].name<<"and the amount of vote is " <<d.can[r].amount <<endl;
flag=1;
}
}
if(flag==0) cout << "The result is none,because the percent of every candidate is below 50%."<<endl;
return 0;
}
void main()
{
Demo t=new demo();
cout << "The candidates are " << t.can[0].name <<endl<<t.can[1].name<<endl <<t.can[2].name <<endl;
cout <<"Please choose one of them:"<<endl;
char c;
cin >> c;
while(c=='a'||c=='b'||c=='c') {n=t.Iseffvote(c,t.can);}
t.Result();
}
但是运行后出现的错误信息提示是:
F:\OOP\demo.cpp(9) : error C2061: syntax error : identifier 'demo'
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ')' before ';'
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ';' before ')'
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ';' before ')'
F:\OOP\demo.cpp(12) : warning C4552: '<' : operator has no effect; expected operator with side-effect
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ';' before ')'
F:\OOP\demo.cpp(13) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.
demo.obj - 1 error(s), 0 warning(s)
希望大侠们帮帮忙啊