Be a Supporter!

arrays

  • 264 Views
  • 4 Replies
New Topic Respond to this Topic
GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
arrays 2006-11-16 10:34:07 Reply

im trying to learn arrays, and i guess they're really different than what im used to. i keep getting the error "too many initializers". heres my code

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

int coinValue[] = {100, 25, 10, 5, 1};
char coinName[] = {"dollar", "quarter", "dime", "nickel", "penny"};

both array lines are wrong and both are getting errors. what am i doing wrong? os there a tutorial for array, anyone? i skimmed c++: main and didnt find one

Xivectro
Xivectro
  • Member since: Oct. 5, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to arrays 2006-11-16 12:08:32 Reply

I am no programming guru and have never, seriously, checked out C++ till just now.
So i was bored and decided to "try" to help you, and heres what "might" the problem.

"both array lines are wrong and both are getting errors. what am i doing wrong?"

error "too many initializers":
The compiler encountered more initializers than were allowed by the declaration being initialized.

Array Syntax:
type name [elements];

i honestly have no clue, but i'm guessing you should assign a value in your brackets equal to the number of items in your array??
Or it could be something completely different.

Consider what your doing, how you're doing it, & the code you're using; maybe this guide will help?
C++ Arrays: Tutorial

Jordan
Jordan
  • Member since: Apr. 23, 2006
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to arrays 2006-11-16 12:10:58 Reply

Try this:
int coinValue[5] = {100, 25, 10, 5, 1};

elbekko
elbekko
  • Member since: Jul. 23, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to arrays 2006-11-16 12:13:09 Reply

I have a feeling that
char coinName[] = {"dollar", "quarter", "dime", "nickel", "penny"};
is going to throw even more errors. You'll need a string array, not a char array.
char array = string =)

string coinName[5] = {"dollar", "quarter", "dime", "nickel", "penny"};

should be correct I think.


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature
GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to arrays 2006-11-16 14:29:06 Reply

thanks it worked!