1

I want to realize math operations and write in the array, I send parameters as int, but error says invalid types 'int[int]' for array subscript.

string clients[5][2];
string products[7];
string strPrices[7];
int prices[7];
int resumen[5][2];
void selectOption(int i, int opc, int cantidad){

    if(opc==1){
        clients[i][1] = ""+cantidad+products[0];
    } else if(opc==2){
        clients[i][1] = ""+cantidad+products[1];
    } else if(opc==3){
        clients[i][1] = ""+cantidad+products[2];
    } else if(opc==4){
        clients[i][1] = ""+cantidad+products[3];
    } else if(opc==5){
        clients[i][1] = ""+cantidad+products[4];
    } else if(opc==6){
        clients[i][1] = ""+cantidad+products[5];
    } else{
        clients[i][1] = ""+cantidad+products[6];
    }

    prices[i][0] = i+1; //--- error: invalid types ‘int[int]’ for array subscript
    prices[i][1] = prices[i]*cantidad; //--- error: invalid types ‘int[int]’ for array subscript
}
2
  • For your arrays use : std::vector<int>, for strings use std::string and to convert strings to integers use std::stoi (en.cppreference.com/w/cpp/string/basic_string/stol). Commented Sep 26, 2022 at 7:45
  • 1
    You have to decide is prices a 1D array or a 2D array? Because at the moment half of your code says it's a 1D array and the other half says it's a 2D array. First decide what you really want it to be, then fix the code. Commented Sep 26, 2022 at 7:51

1 Answer 1

1

From the code you posted above, I suppose that prices is an int array, and subscribing an int array will get an int, which means prices[i] is a legal expression and its type is int. However, int is not subscribable, which means prices[i][0] is not a legal expression, so the compiler is reporting an error.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.