fix my array position!

Here is problem i want to make an array with a range of number from 1-9 only. So if the user entered more than or less than the number indicated it will be error and ask the user to reinput the data. So far my code can be used to do so that if the user enter the number one by one... But if the user entered all the number in one shot the reentered value will be prompt to the back automatically for some reason...Let say 10,2,3,4 which was suppose to be 1,2,3,4 became 2,3,4,1 instead... here is the code:

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
#include<stdio.h>
void main()
{
int num[4][4];
	int row,col,x,y;

	for(row=0;row<4;row++)
	{

		printf("Enter Row %d: ",row);

		for(col=0;col<4;col++)
		{
		x=row;
		y=col;
		scanf("%d",&num[row][col]);

		if(num[row][col]>9 || num[row][col]<0)
		{
		
			printf("The array %d,%d you've entered got error\n plz reenter the value\n",row,col);
			scanf("%d",&num[x][y]);
		}
		
		}
	}

}
You can use streams and std::cin.ignore
to control input to a two dimension array you need something like nested loops and to prevent double digit input you need something like a while loop. So...

prompt"enter the first digit
enter " digit"
while (digit>0 && digit<10)//allow only 1 - 9
{
for(int i=0;i<number of rows;i++)//controls row number
for (int j=0;j<number of columns;j++)//controls column number
{
num[i][j] = digit;//fill a row
enter "digit";}

}
error
Topic archived. No new replies allowed.