Put variable into variable name

So let's say I have the following integers: iX1, iX2, iX3.... iX1000 (theres 1,000 integers)

Now I want my program to assign 0 to whichever one the user selects.
So the user enters "2", that means it should do iX2 = 0;
But how can I write code for that?

I can't do
if(iUserInput = 1)
iX1=0;
if(iUserInput = 2)
iX2=0;

that would be wayyyy too long,
isn't there for a way for me to stick in a variable into the name?

like this: iX[iUserInput] = 0;
thanks

if not,what's an effective way to write code that isn't 1,000 lines long?
Have you considered creating an int array, filling it with a counter in a for loop, and writing a zero over the user input number in the correct space in the array?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main (){

int x = 0;
int userinput;
int arr[1000];

for (int i = 0; i < 1000; i++)
	{ 
	arr[i] = x;
	x++;
	}

cin >> userinput;

arr[userinput] = 0;

return 0;
}
Topic archived. No new replies allowed.