0
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int t;
    cin >> t;
    char g;
    vector<int> b(t);
    vector<int> c(t);
    for(int a=0; a<t ; a++)
        {
        cin>>b[a]>>g>>c[t];
        //this g was not required as a space as input is to be given
    }
    for(int a=0; a<t ; a++)
        {
        float z,x;
        int q,w,c,v,ans=0;
        z=sqrt(b[a]); 
        x=sqrt(c[a]);
        //here the line above error is coming`enter code here`
        c=ceil(z);
        v=ceil(x);
        q=z;
        w=x;
        if((c==v)&&(v!=w))
            {
            ans=0;
        }
        else if((c==v)&&(v==w))
            {
            ans=1;
        }
        else
            {
            while(c<=v)
                {
                ans++;
                c++;
            }
        }
        cout<<ans<<endl;
   }
    return 0;
}`

I know this error but i dot understand why it is coming in this code... please help...

I am not declaring 1 dimensional array and using like a 2 dimensional array so that i m getting this error...please help the error I m getting is

invalid types 'int[int]' for array subscript
1
  • In your for loop you created a new integer variable c. This will mask out the original vector c. Commented Feb 7, 2016 at 14:52

1 Answer 1

2

In your for loop you created a new integer variable c. This will mask out the original vector c.Since the new c does not support operator[] you get the error. I would solve this problem by using more descriptive variable names especially for your vectors and make sure the name does not match the local integer in your for loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.