I need to initialize all vector values at 0
int FilaA[9] = {0};
Better to go programming a loop, right?
By the way, in C ++ (and already in C99 and later) it is legal to declare variables within the loops:
for( int i=0; i<9; i++ )
// ^^^
and ask for the column data
No need to use temporary variables to recover keyboard values:
// Esto...
scanf("%d", &ValorIngresado);
FilaA[Columna]=ValorIngresado;
// ... queda asi mas limpio ...
scanf("%d",&FilaA[Columna]);
Although, on the other hand, you are programming in C ++ ... so I recommend using the C ++ own syntax:
#include <iostream>
std::cout << "Digite la columna:\n";
std::cin >> Columna;
std::cout << Digite un valor entre 1-9 que desea ingresar en la posicion [" << Columna << "]: \n\t";
std::cin >> FilaA[Columna];
And, to finish off the move, consider contemplating if the data entered by the user is correct (regardless of whether you use version C or the C ++ version):
#include <limits>
do
{
std::cout << "Digite la columna:\n";
std::cin >> Columna
if( std::cin.fail() ) // No se ha introducido un numero
{
// Descartar lo que haya en el buffer de entrada
std::cin.ignore(std::numeric_limits<int>::max());
// Limpiar los flags de error
std::cin.clear();
}
}
while ( Columna < 0 || Columna > 8 );
std::cout << Digite un valor entre 1-9 que desea ingresar en la posicion [" << Columna << "]: \n\t";
std::cin >> FilaA[Columna];
but in the final impression gives something that I do not see sense, change 4 values instead of only the one that was entered the data
printf("%d %d %d %d %d %d %d %d "), FilaA[0], FilaA[1], FilaA[2], FilaA[3], FilaA[4], FilaA[5], FilaA[6], FilaA[7], FilaA[8];
// ^ AQUI
This parenthesis ends the function printf
. As you do not pass any parameters and you are having good luck, the function is limited to printing garbage. The quick solution is to move that parenthesis to the end of the line:
printf("%d %d %d %d %d %d %d %d ", FilaA[0], FilaA[1], FilaA[2], FilaA[3], FilaA[4], FilaA[5], FilaA[6], FilaA[7], FilaA[8]);
Although you could also get a more manageable code and less prone to errors if you use loops:
for( int i=0; i<9; i++ )
printf("%d ",FilaA[i]);
And it would be even better if you use the functionality of C ++:
for( int i=0; i<9; i++ )
std::cout << FilaA[i] << ' ';