Hello and thank You in advance,

I have been struggling quite a bit with this so any help is greatly appreciated.

I need to add 3 global variables with an unknown amount of elements to a program.

As far as I know and as far as I can find in my book the way to declare an unknown amount of elements is to leave the brackets blank

ie..

char retail[];

but, I get an error stating that the storage size isn't known...

how do I leave the array up to the user to define with input ?

Colin

You can only use that if you're assigning when defining, i.e.

int thing[] = { 4, 8, 15, 16, 23, 42 };

If you're not assigning you must use a constant size.

Alternatives.
Use pointers and dynamically allocate a size you want.
Use scalable array containers, like vectors, list or maps.

try char * retail.

But you will have to allocate memory before the use of it. BTW why do you
need it to be global?

You can only use that if you're assigning when defining, i.e.

int thing[] = { 4, 8, 15, 16, 23, 42 };

If you're not assigning you must use a constant size.

Alternatives.
Use pointers and dynamically allocate a size you want.
Use scalable array containers, like vectors, list or maps.

Thank you for the input

try char * retail.

But you will have to allocate memory before the use of it. BTW why do you
need it to be global?

We are building a point of sale system for a class project and each menu option (ie. cashier module , book info ) is written as individual functions.

And this weeks addition to the project is to create parallel arrays that will hold the book info information (ie.. author, retail price, isbn etc.. ) The book directs us to include global arrays that will hold this information and than pass them as arguments into the bookInfo function..

Three of the arrays are going to hold information that is not know yet. leaving the brackets blank seems to work when I include them in the functions parameters, but not when I am declaring.

I am also a little confused as how to include multiple arrays in one functions parameters properly ...

when I include the arrays in the parameter list do they need a data type as well ?

ie .. void bookInfo (retail [5][10] , char , author [5][25], char , etc )

or is this data type declaration taken care of by the initial definition of the array ?

The book directs us to include global arrays that will hold this information and than pass them as arguments into the bookInfo function..

Getting you into the really bad habits early, eh? I don't fault you in any way for the text that the instructor chose, but what book is it may I ask? (forgive me if this is a little OT)

Getting you into the really bad habits early, eh? I don't fault you in any way for the text that the instructor chose, but what book is it may I ask? (forgive me if this is a little OT)

starting out with c++ by TONY GADDIS. the funny thing is we just went over the topic of global arrays in class and why NOT to use them, and now our book is instructing us to do so ???? ... makes a whole lot of sense to me ...

in any event, do you think I should just give the array that has an unknown size enough space to accommodate anything the user enters ? Because I don't think we are supposed to be using & or * yet ... and they confuse the &&%%*%^&$&$$& out of me so far ..

This article has been dead for over six months. Start a new discussion instead.