Invalid Types Float[Int] for Array Subscript
I Had Been Doing a Question. I Have Not Written the Function Code Here Because I Am Getting an Error: Invalid Types Float[Int] for Array Subscript in the...
I had been doing a question. I have not written the function code here because I am getting an error:
invalid types float[int] for array subscript in the following code snippet.
Please tell me why is this error coming?
#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;
}
Any help would be appreciated.
2 Answers
In your for loop, it should be
arr[i]
not
a[i]
since your named your array 'arr'.
You have to show us the error you're getting. From what I see, you're treating a as an array while it is declared to be a scalar float (as mentioned by user @songyuanyao)