【发布时间】:2014-03-23 07:27:27
【问题描述】:
因此,我删除并重新输入了错误所指的行,关闭并重新打开了 Visual Studio,并查看了此处发布的几个错误,这些错误与我的措辞相同/相似。
我感觉这是 Visual Studio 的一个错误,因为即使我删除了所有代码,保存并重新编译后,它仍然在同一行出现了一个不再存在的错误。
“IntelliSense:“void”类型的值不能分配给“double”类型的实体”
以防万一这不是工作室的错误,我想我会询问有关我的代码中的什么可能导致此错误的任何想法?代码中间的块引用是它引用该错误的行。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main ()
{
//Declarations of vectors and basic holders for input transfer
vector<string> candidateName;
string inputString;
vector<int> candidateVotes;
int counter,inputInt,totaledVotes;
double percentage;
vector<double> candidatePercentage;
//Method declaration for calculations
void calculatePercentage (int, int, int);
//User input to gather number of candidates, names, and votes received.
cout <<"How many candidates need to be input?";
cin>>counter;
for(int i = 0;i<counter;i++)
{
cout<<"Please enter the candidate's last name.";
cin>>inputString;
candidateName.push_back(inputString);
cout<<"Please enter the number of votes "<<candidateName[i]<<" received.";
cin>>inputInt;
candidateVotes.push_back(inputInt);
totaledVotes+=candidateVotes[i];
}
for(int i = 0;i<counter;i++)
{
//Problem here vvv
percentage = calculatePercentage(totaledVotes, candidateVotes[i], i);
//Problem there ^^^
candidatePercentage.push_back(percentage);
}
}
double calculatePercentage (int totalVotes, int candidateVotes, int rosterNumber)
{
int percentage;
percentage = candidateVotes/totalVotes;
percentage*=100;
return percentage;
}
【问题讨论】:
标签: c++ methods vector intellisense