IntelliSense:无法将类型为“ void”的值分配给类型为“ double”的实体

希瑟·T

因此,我删除并重新输入了错误所指向的行,并关闭并重新打开了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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法将类型为int的值分配给类型为node的实体

错误:无法将类型“ double *”的值分配给类型“ double”的实体

错误:无法将类型“ void *”的值分配给类型“ int **”的实体

无法将类型'myFuncDef *'分配给'void(*)(double *,double *)'

如何解决“状态错误(活动)E0513无法将类型为“ const wchar_t *”的值分配给类型为“ wchar_t *”的实体”

无法将“Double”类型的值分配给“Binding<Double>”类型

无法将类型'()-> Void'的值分配给'(()-> Void)!'

有人可以找到错误“无法将“void”类型的值分配给VScode中“int”类型的实体的原因吗?

获取“无法将类型 'CLLocationDegrees'(又名'Double')的值分配给类型'Int'”错误(Swift 4)

无法查询属性为double类型的实体

类型const char *类型的值不能分配给char *类型的实体吗?

无法将类型'((UIViewController ?, NSError?)-> Void'的值分配给类型'((UIViewController ?, Error?)-> Void)?

类型'null'不能分配给类型'()=> void | 空值'

类型“ const char *”的值不能分配给类型“ LPSTR”的实体

“int”类型的值不能分配给“Node<int> *”C/C++(513) 类型的实体

快速将String类型数组转换为Float类型数组无法将'String'类型的值分配给'Double'类型的下标

Flutter:无法将类型为lib1 :: Object的值分配给类型为lib2 :: Object的变量

Swift 4:无法将类型'(_)-> Void'的值分配给类型'(()->())吗?'

我该如何解决无法将'Double'类型的值分配给'String'吗?在Swift3中

Flutter 无法将参数类型 'Listenable' 分配给参数类型 'Animation<double>

Flutter 2.2.3:无法将参数类型“Animation<dynamic>”分配给参数类型“Animation<double>”

flutter firebase googlesign in 说 - 类型为“GoogleSignInAccount?”的值?无法分配给“GoogleSignInAccount”类型的变量

无法将“STPPaymentMethodCardParams”类型的值分配给“STPCardParams”类型

无法将类型“ Int”的值分配给类型“ Int?”

无法将类型“ CGPoint”的值分配给类型“ CGFloat”

无法将类型“ AppDelegate”的值分配给类型“ CLLocationManagerDelegate?”

无法将“String”类型的值分配给“UILabel”类型

无法将“()”类型的值分配给“UIView?”类型

无法将类型“ UIViewController”的值分配给类型“ UITabBarController?”