#118902 - Dox-999 - Sun Feb 18, 2007 2:39 am
Hi guys I am still learning C++ and I am doing arrays so I decied to practise this by making a table where the user could input 1 number (I know it's not very practical but anyway). When I ran the program the number I input worked but all the other spaces in the table have random numbers in there. This is my code:
is there a way for all the integers I don't use to just stay blank?
Thanks :)
Code: |
#include <iostream>
using namespace std; int main() { int x; int y; int array[2][2]; cout<<"Insert a number into this table:\n\n 0 1 2\n0[][][]\n1[][][]\n2[][][]"; cout<<"\n\nEnter (in this order) the x value the y value and the number you wish to input (e.g. 1 2 62): " ; cin>> x >> y >> array[x][y]; cin.ignore(); cout<<"["<< array[0][0] <<"]["<< array[0][1] <<"]["<< array[0][2] <<"]\n["<< array[1][0] <<"]["<< array[1][1] <<"]["<< array[1][2] <<"]\n["<< array[2][0] <<"]["<< array[2][1] <<"]["<< array[2][2] <<"]\n"; cout<<"\nAgain: "; cin>> x >> y >> array[x][y]; cin.ignore(); cout<<"["<< array[0][0] <<"]["<< array[0][1] <<"]["<< array[0][2] <<"]\n["<< array[1][0] <<"]["<< array[1][1] <<"]["<< array[1][2] <<"]\n["<< array[2][0] <<"]["<< array[2][1] <<"]["<< array[2][2] <<"]\n"; cin.get(); } |
is there a way for all the integers I don't use to just stay blank?
Thanks :)