Multi Dimensional Arrays

So Im trying to create this periodic table of elements and Im having a hard time trying to display this code as the periodic table itself. Any sort of help will be much appreciated. Thanks and more power.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 #include <iostream>
#include <string>
#include <bits/stdc++.h> 

using namespace std;
int main()

void

{
	
	string ptoe [10][18] = 
	{
		{" H", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "He",  },
		{"Li", "Be", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", " B", " C", " N", " O", " F", "Ne",  },
		{"Na", "Mg", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "Al", "Si", " P", " S", "Cl", "Ar",  },
		{" K", "Ca", "Sc", "Ti", " V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",  },
		{"Rb", "Sr", " Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", " I", "Xe",  },
		{"Cs", "Ba", ">1", "Hf", "Ta", " W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Ti", "Pb", "Bi", "Po", "At", "Rn",  },
		{"Fr", "Ra", ">2", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og",  },
		{"  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ",  },		
		{"  ", "  ", ">1", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu",  },
		{"  ", "  ", ">2", "Ac", "Th", "Pa", " U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr",  },	
	};
		
// this is my problem right here:

for (int i = 0; i < 10; ++i)
cout<<ptoe[i]<<endl;
    for (int j = 0; j < 18; ++j)
        cout << ptoe[j] <<endl;

	
	return 0;
}
Line 8: "void"
Why?

1
2
3
4
5
6
for (int i = 0; i < 10; ++i)
{
    for (int j = 0; j < 18; ++j)
        cout << ptoe[i][j];
    cout << endl;
}


Do it like that instead. Notice that multiple statements in a for loop require it to be wrapped with { and } .
Yeah sorry bout that void i was thinking of creating a function instead but it seems that it will be more complicated if forgot to remove it. Ill try this now thanks man big help.
Thanks man it works just as i needed. Turns out braces are really a big thing.
Yep, same thing with if statements.

Compare:
1
2
3
if (condition)
    in_if_statement();
not_in_if statement();


1
2
3
4
5
6
if (condition)
{
    in_if_statement();
    still_in_if_statement();
}
not_in_if_statement();


Note whitespace (indentation) doesn't matter, but should be there for legibility for other humans.
Last edited on
Topic archived. No new replies allowed.