I do not know what you did with map[5]={0,0,1,2,3]};. The space between "map" and "[5]" and also between "[5]" and "=", I do not think it is just a space, but maybe a tab?
Also the "]" after the "3" should not be there.
From C++11 you can write the line as map[5]{ 0, 0, 1, 2, 3 };.
Again choose a better name than map that is more descriptive of what it is.
You can't write to more than one line at once.
Write the first line, then output a newline, and then the 2nd line.
This might require 2x loops (or an inner and outer loop, there's multiple ways to do this).
Also, your lines 7, 9, 11, and 13 aren't doing anything.
I do not know of any way to print two different lines in one for loop. If you need two different lines than use two for loops with the case statements generating two different lines, but one line at a time.
Had I noticed the second line earlier I would have suggested two for loops.
When outputting to standard out, you can only do it line-by-line.
What you need to do here is construct your entire output in memory first, as a pair of strings, and then, one you've finished constructing them all, then print the lines out.
So for each value in your array, you modify - in memory - your first string, and then modify - again, in memory - the second string.
Then, once you've finished processing all the array elements, then you print out the first string, followed by the second string.
The important point is that you don't output anything, until after you've finished processing all the array elements, and have completely constructed both strings.
blacksjacks, what you mean is:
- you have a C-style array of ints
- where the only admitted digits are 0, 1, 2 and 3,
- and you want to apply a two steps conversion such as - 0 becomes @@ and later @@ becomes @!
- 1 becomes ## and ## remains ##
- 2 becomes $$ and later $$ becomes &*
- 3 becomes ** and ** remains **
- but you want both transformations to take place in the same line?
@Enoizat No, I don't think so. The output is supposed to be two lines. For each given number in the array, a certain pair of characters is appended to the first line, and another pair of characters is appended to the second line.
@MikeyBoy, thank you.
What can I say? «Oooooh!» :-)
I must admit I hadn't the foggiest notion what you were talking about :-/
Now I can see that, ok, it's an exercise that makes sense.
This in an example where data is more appropriate than code. Store the int-to-string mapping in an array. Since there are two different mappings, use two different arrays.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
using std::cout;
int main()
{
constchar *line1[] = { "@@", "##", "$$", "**" };
constchar *line2[] = { "@!", "##", "&*", "**" };
int indices[5] = {0, 0, 1, 2, 3 };
for (int i : indices) cout << line1[i];
cout << '\n';
for (int i : indices) cout << line2[i];
cout << '\n';
}