【发布时间】:2014-11-10 07:04:37
【问题描述】:
我收到如下错误消息:
calculatewinner Candidate 的未解决的外部符号错误
这是我的代码:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
void headerforelection();
void getNamecalculatetotal(ifstream& in, string candidates[], double Votes[], double percentvotes[]);
void getNamecalculatetotal2(ifstream& in, string fname[], double Votes[], double percentvotes[]);
void allvotes(double []);
void Votesrecievedpercentage(ifstream& in, char Candidate[], double Votes[], string fname[], double percentvotes[]);
void Votesrecievedpercentage2(double Votes[], string fname[], double percentvotes[]);
void calculatewinner(string fname[], double Votes[]);
void headerforelection();
int main()
{
ifstream in = ifstream();
in.open("Votes.txt");
ofstream out = ofstream();
out.open("outputs.txt");
char winner();
char Candidate();
string fname[5];
double Votes[5];
double percentvotes[5];
double total = double();
headerforelection();
while (!in.eof())
{
getNamecalculatetotal(in, fname, Votes, percentvotes);
Votesrecievedpercentage2(Votes, fname, percentvotes);
}
allvotes(Votes);
calculatewinner(fname, Votes);
}
void getNamecalculatetotal(ifstream& in, string fname[], double Votes[], double percent[])
{
double total = double();
for (int i = 0; i < 5; i++)
{
in >> fname[i] >> Votes[i];
total = total + Votes[i];
}
for (int j = 0; j < 5; j++)
{
percent[j] = (Votes[j] / total) * 100;
}
}
void headerforelection()
{
std::cout << fixed << setfill(' ') << left << setw(10) << "Candidate"
<< right << setw(20) << setprecision(0) << "votes Recieved"
<< right << setw(20) << setprecision(2) << "% of Total Votes" << std::endl;
std::cout << endl;
}
void Votesrecievedpercentage2( double Votes[], string fname[], double percentvotes[])
{
for (int b = 0; b < 5; b++)
{
std::cout << fixed << setfill(' ') << left << setw(10) << fname[b]
<< right << setw(16) << setprecision(0) << Votes[b]
<< right << setw(16) << setprecision(2) << percentvotes << std::endl;
}
}
void allvotes(double Votes[])
{
double total = double();
for (int i = 0; i < 5; i++)
{
total = total + Votes[i];
}
std::cout << setfill(' ') << left << setw(22) << "Total" << setprecision(0) << total << std::endl;
}
void calculatewinner(string fname[], double Votes[])
{
{
int winner = 0;
for (int l = 0; l, 5; l++)
{
if (Votes[l] > Votes[winner])
{
winner = l;//3
}
}
}
char winner();
char Candidate();
std::cout << std::endl;
std::cout << Candidate << "Is The Winner" << fname << "." << std::endl;
}
【问题讨论】:
-
你想用这条线做什么:
char Candidate();? -
ifstream in = ifstream();这种分配是完全错误的。要初始化输入流,请使用ifstream in("Votes.txt");,输出流也一样。