2016-12-28 92 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

這是一條評論,而不是答案 –

相關問題