2

So, I'm getting the above error (in the title) but for some reason it's only throwing this error on the second loop. Notice the first and second loop I have using the customer variable works absolutely fine, no errors thrown or anything. But on that last loop, the output[customer][charge] array, there is a red line under output[customer] that says "Subscripted value is not an array, pointer or vector". I am using xcode, Mavericks OSX. All of my arrays are defined elsewhere, and have worked perfectly the whole length of the program until now. There are some other operations going on in the program, but they have nothing to do with this loop, so I just posted the code that was giving the error. Again I'll say, the charges[customer][month][charge] loop works fine, but the output[customer][output] is not working.

P.S. You probably will think the logic behind keeping all this data in numerically indexed arrays is dumb, but it is for a school project. So don't lecture me about how this program is logically inconsistent or whatever. Thanks!

string headings[3][7];
string chargeLabels[3] = {"Electricity :","Water: ","Gas: "};
string outputLabels[5] = {"Subtotal: ","Discount: ","Subtotal: ","Tax: ","Total: "};
double charges[3][3][3];
double output[3][5];

for(int customer=0; customer<3; customer++)
{
    for(int heading=0; heading<5; heading++)
    {
        cout << headings[customer][heading];
    }

    for(int month=0; month<3; month++)
    {
        cout << chargeLabels[month];

        for(int charge=0; charge<3; charge++)
        {
            cout << charges[customer][month][charge] << ", ";
        }
        cout << endl;
    }
    for(int output=0; output<5; output++)
    {
        cout << outputLabels[output];
        //error is below this comment
        cout << output[customer][output] << endl;
    }
}

2 Answers 2

4

Inside the for statement:

for(int output=0; output<5; output++)
{

You declared another variable int output which shadows the double output[3][5] with the same name outside the for statement.

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

Comments

2

Here's your problem:

double output[3][5];
for(int output=0; output<5; output++)

You're reusing output as a variable name twice.

So when you try to access it here:

cout << output[customer][output] << endl;

You're accessing the local output, which is just an int.

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.