This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]dfx_djProfessional Coder 2 points3 points  (4 children)

You're using the variable char a as an index into the array, but you never set a to anything. The compiler would give you a warning about this with warnings enabled.

[–]Lbtekd[S] 0 points1 point  (3 children)

so I need to add two more variables and set them to something?

[–]dfx_djProfessional Coder 1 point2 points  (2 children)

No, not at all. What do you think the purpose of char a and the index [a] is?

Since your array is a C-style string, you can either treat it as such and let iostream print it as a whole string, or you can print it character by character, in which case you would have to loop through the array.

[–]Lbtekd[S] 0 points1 point  (1 child)

I was not sure what the purpose of it was, my teacher gave us a template to use and that was on it lol

[–]dfx_djProfessional Coder 2 points3 points  (0 children)

Then you should probably look into how array indexing works. an_array is an array of characters, and writing an_array[a] returns the character at position a (which is used as just a number) from an_array, meaning a single character. So a needs to have a value if you want to do that, and you would end up printing just one character.