I recently started programming in C++, and I need to make a "table" of soccer teams that looks like this:
The part marked in blue is a 4x8 matrix that is filled with data (which can change) that is obtained from another part of the code that I already have done.
What is marked in yellow must be fixed information.
And the problem is that I don't know exactly how to make the part that is marked in red stay on par with the matrix. Because I also have to make the table specifically ordered so that the team with the most points is first and so on with the others. (For example):
At the moment the code (specifically for this part) I have it this way:
cout << "\n\tEquipo" << setw(6) << "PJ" << setw(4) << "PG" << setw(4) << "PE" << setw(4) << "PP"
<< setw(4) << "GF" << setw(4) << "GC" << setw(5) << "Dif" << setw(5) << "Pts" << endl; (Todo esto es una misma línea de código, lo que pasa es que ahora mismo que estoy escribiendo esto se ve así, luego de esta línea viene lo de abajo)
cout << "1." << Equipo1 << endl;
cout << "2." << Equipo2 << endl;
cout << "3." << Equipo3 << endl;
cout << "4." << Equipo4 << endl;
for(int i=0; i<4; i++){
for(int j=0; j<8; j++){
cout <<"|"<<Matriz[i][j]<<"|";
if(Matriz[i][j] >= 0){
cout <<" ";
}
if(Matriz[i][j] < 0){
cout <<"";
}
}
cout << endl;
}
But obviously this is wrong because when you run it it looks like this (and obviously it's not ordered either because honestly I don't know very well how to do it):
That is why someone can tell me please, how to make it be next to or "attached" to the part where the name of the teams appears and also that they are ordered.
Well, as you have it, you can, as a hack, create a function that prints one of the rows of the matrix:
With which now you no longer have to repeat the code when printing the 4 rows:
However, the code would be more elegant if you created a data structure that also stores the team name:
Although if it is a requirement to continue using the array, you could also reference it:
In this case the array could be created like this:
Although it would be preferable to use a container of the STL, type
std::vector
ostd::array
In any case, you could now print the entire table with a single loop: