因此,我删除并重新输入了错误所指向的行,并关闭并重新打开了Visual Studio,并仔细查看了此处显示的与我的措辞相同/相似的错误。
我感觉这是Visual Studio的错误,因为即使我以代码方式删除了所有内容,保存并重新编译后,它仍在不再存在的同一行上给出了错误。
“ IntelliSense:不能将类型为“ void”的值分配给类型为“ double”的实体”
万一这不是studio的错误,我想我想问一下我的代码中可能引起此错误的任何想法吗?代码中间的blockquote是该错误所引用的行。
#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;
}
你有这个声明
void calculatePercentage (int, int, int);
那你做
percentage = calculatePercentage(totaledVotes, candidateVotes[i], i);
但是您只是声明该函数不返回任何东西。
而且以后也与实际定义不符:
double calculatePercentage (int totalVotes, int candidateVotes, int rosterNumber)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句