Author Topic: Invalid array subscript  (Read 2826 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Invalid array subscript
« on: November 09, 2011, 02:59:43 am »
Code: [Select]
#include <stdio.h>

using namespace std;

int main()
{
  int n;
  scanf("%d", &n);

  int avenidas[99];
  int ruas[99];

  int rua;
  int avenida;
  int pizzas;
  int i;
  for (i = 0; i < n; i++)
  {
    scanf("%d %d %d", &rua, &avenida, &pizzas);
    avenidas[avenida] += pizzas;
    ruas[rua] += pizzas;
  }

  int a = 7;
  printf("%d %d\n", avenida[a], rua[0]);
}

This is mostly C, but I'm using g++ to compile (I'll need C++ libraries later), and I'm getting this:

Quote
s.cpp:25:30: error: invalid types ‘int[int]’ for array subscript
s.cpp:25:38: error: invalid types ‘int[int]’ for array subscript

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: Invalid array subscript
« Reply #1 on: November 09, 2011, 01:27:15 pm »
avenida and rua are ints.

avenidas and ruas are the arrays.

Edit: I compiled a corrected version and it works. ;D So what is this code doing, exactly?
« Last Edit: November 09, 2011, 01:31:02 pm by HOMER-16 »

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Invalid array subscript
« Reply #2 on: November 09, 2011, 04:04:06 pm »
avenida and rua are ints.

avenidas and ruas are the arrays.

Edit: I compiled a corrected version and it works. ;D So what is this code doing, exactly?

It's an exercise, but it's now done, thanks to you :)