2016-12-28 831 views
-1

我一直在做一个问题。因为我得到一个错误,我没有在这里写的功能代码:对于数组下标,float [int]类型无效

invalid types float[int] for array subscript in the following code snippet.

请告诉我这是为什么error来了吗?

#include<iostream> 
using namespace std; 
main() 
{ 
    float a,b,p,q,r,s,arr[1000]; 
    int n=1000, minOp; 

    cin>>a; 
    cin>>b; 
    cin>>p>>q>>r>>s; 
    arr[0]=src; 
    for(int i=1; i<n; i++) 
    { 
     if(i%4==1) 
     { 
      a[i]=a[i/4] + p; 
     } 
     else if(i%4==2) 
     { 
      a[i]=a[i/4] - q; 
     } 
     else 
     if(i%4==3) 
     { 
      a[i]=a[i/4] * r; 
     } 
     else if(i%4==0) 
     { 

      a[i]= a[ (i/4)-1]/s; 
     } 
    } 

root = buildTree(arr, n); 
minOp = bfs(root,b); 
cout<<minOp; 
} 

任何帮助,将不胜感激。

+1

'a'是'float',而不是'float'数组。 – songyuanyao

+0

我怀疑你打算在所有你使用''a''的地方使用'arr'。 –

回答

0

在你的for循环中,它应该是

arr[i] 

a[i] 

因为你命名你的数组'常用3'

-2

你必须告诉我们你得到的错误。从我所看到的,你在治疗a作为一个阵列,同时在它被宣布为一个标量浮点(由用户@songyuanyao提到)

+2

这是一条评论,而不是答案 –

相关问题