Hea*_*r T 0 c++ methods intellisense vector
所以,我已删除并重新输入错误引用的行,关闭并重新打开visual studio,并查看此处发布的几个错误,显示与我的相同/相似的措辞.
我觉得这是视觉工作室的一个错误,因为即使在我删除了所有代码,保存和重新编译的内容之后,它也会在同一行上出现错误,不再存在.
"IntelliSense:类型为"void"的值无法分配给"double"类型的实体
为了防止它与工作室的错误,我想我会问我的代码中可能导致此错误的任何想法?代码中间的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;
}
Run Code Online (Sandbox Code Playgroud)
你有这个声明
void calculatePercentage (int, int, int);
Run Code Online (Sandbox Code Playgroud)
然后你做
percentage = calculatePercentage(totaledVotes, candidateVotes[i], i);
Run Code Online (Sandbox Code Playgroud)
但是你刚刚声明函数没有返回任何东西.
它也与以后的实际定义不符:
double calculatePercentage (int totalVotes, int candidateVotes, int rosterNumber)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5519 次 |
| 最近记录: |