English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hey im supposed to use an array here and its giving me an error im not sure how to fix
the error is in the following line

cout< print(1, 2, votes[12]);

it says that votes has an undeclared identifier, but if i try to use int or double it says type unexpected
help plz?

2007-03-19 19:58:32 · 4 answers · asked by Alex P 2 in Computers & Internet Programming & Design

4 answers

The whole print line is in trouble...

In C (and other languages) you have to declare your variables before you can use them. So, to declare an array, you need to know what type of data the array will hold (char, int, double, etc.) and how many you'll need. For example, if your array is going to have ten "short" values, you could do the following:

short myArray[10];

This would be done at the beginning of the program just after main() (or prior to main if it's to be a global variable.)

So, once you've declared the array, you need to assign values. (You can do it at the time of declaration too.) If I want to put some numbers in, I could do:

myArray[0]=1;
myArray[1]=33;
myArray[4]=99;

and so on. To print them, you'll want to use cout something like:

cout << "First array element: " << myArray[0] << endl;

If you put all of these pieces together, that should be all you need.

2007-03-19 20:03:40 · answer #1 · answered by BigRez 6 · 0 0

Yes, you should have declared votes as a variable somewhere earlier in your code, something like:
int votes[13];

And how is print() defined, i.e., what's the prototype for your print function?

2007-03-20 03:12:18 · answer #2 · answered by rongee_59 6 · 0 0

no give any answer

2007-03-20 03:08:20 · answer #3 · answered by virender k 1 · 0 1

Show us the declaration for votes please.

2007-03-20 03:02:01 · answer #4 · answered by csanon 6 · 0 0

fedest.com, questions and answers