how i create alphanumeric table?

how i create a table with alphanumeric data? like a[1]=one?
i type this

void main(){
const char a[]={"one","two","three","four","five","six","seven","eight","nine"};

int n;
cin >> n;
if(n>9)
{cout<<a[n]<<endl;}
else
{cout<<"greater than 9"<<endl;}


}
and shows me those errors
Error 1 error C2078: too many initializers 2 IntelliSense: expected a '}'

Last edited on
You created an 1 dimensional array of chars but are using initializing it like its a 2 dimensional array. Why not use an array of strings instead? It would be much easier than what you are currently attempting.

Reference: http://www.cplusplus.com/reference/string/

To accomplish what your currently attempting:
1
2
3
4
5
int main() {
    const char a[9][5] = { {'o', 'n', 'e' },
                         {'t', 'w', 'o' } };
return 0;
}
Last edited on
Change
 
    const char a[]
to
 
    const char * a[]
@evdo

1
2
3
4
5
6
int n;
cin >> n;
if(n>9)
{cout<<a[n]<<endl;}
else
{cout<<"greater than 9"<<endl;}


Line 3 should be if(n < 9 ) NOT greater than.
thanks guys..you are really helpfull..!!
@whitenite1 you are right, my mistake.. i write the code 2 pm...
Last edited on
Topic archived. No new replies allowed.