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 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

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)

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest