Program expects a bracket, but there is one there already there

472 views Asked by At
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

#define ARRAYSIZE  15;


int main(void)
{
    //things needed
    ifstream infile;
    ofstream outfile;

    double xArray[ARRAYSIZE];


}

As you can see, my code should be in order but my program keeps telling me it expects a '[' where the xArray[ARRAYSIZE] is. By the way I'm using microsoft visual studio 2013.

3

There are 3 answers

4
nhgrif On
#define ARRAYSIZE 15

Take the ; out of the #define.

With your #define written as is,

double xArray[ARRAYSIZE];

translates to

double xArray[15;];

The compiler expects a ] before the first ;.


Doing this:

const int ARRAYSIZE 15;

might be better...

0
Bryan Chen On

after preprocess, your code is kind of

int main(void)
{
    //things needed
    ifstream infile;
    ofstream outfile;

    double xArray[15;];  // replace ARRAYSIZE with 15;
}

so you have to remove ; in #define

#define ARRAYSIZE  15
0
Nathan On

#define ARRAYSIZE 15;

Define will substitute ARRAYSIZE with whatever is there next to it.

So in this case it will substitute ARRAYSIZE with 15;

So all you need to do is just remove the semi-colon in the define statement