0

Hi guys, I need some help with arrays.

#include <iostream>
#include <ctime>
using namespace std;

void constructArray (int [], int);
void printArray (int [], int);

const int MAX = 30;
int sizeArray = rand() % MAX;

int main()
{
    srand(time(NULL));
    
    int makeArray [sizeArray];
    
    constructArray [makeArray, sizeArray];
    printArray [makeArray, sizeArray];
    
    system ("pause");
    return 0;
    
}

void constructArray (int makeArray [], int size)
{
     for (int i = 0; i < size; i++)
     makeA [i] = rand () % size;
     
     
 }
 
void printA (int makeArray [] , int size)
{
     for (i = 0; i < sizeA; i++)
     cout << makeA[i] << " ";
     
     
 }

I keep getting a compile error when trying to run it.
I think that my declaration is wrong but can't figure out what's wrong.
Thanks for helping.

Edit: Forgive my eyesight, spotted the [] instead of ()
Haha...

2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by SpS
1

Hi guys, I need some help with arrays.

#include <iostream>
#include <ctime>
using namespace std;

void constructArray (int [], int);
void printArray (int [], int);

const int MAX = 30;
int sizeArray = rand() % MAX;

int main()
{
    srand(time(NULL));
    
    int makeArray [sizeArray];
    
    constructArray [makeArray, sizeArray];
    printArray [makeArray, sizeArray];
    
    system ("pause");
    return 0;
    
}

void constructArray (int makeArray [], int size)
{
     for (int i = 0; i < size; i++)
     makeA [i] = rand () % size;
     
     
 }
 
void printA (int makeArray [] , int size)
{
     for (i = 0; i < sizeA; i++)
     cout << makeA[i] << " ";
     
     
 }

I keep getting a compile error when trying to run it.
I think that my declaration is wrong but can't figure out what's wrong.
Thanks for helping.

Edit: Forgive my eyesight, spotted the [] instead of ()
Haha...

Function call operator is () not []. There are few undeclared variables and some variables with incorrect names.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.