While the other answers are correct in telling you what the problem is, they miss out on giving you an actual way to declare dynamic arrays.
From the topic being "topological sorting", I assume that you only were testing when you declared your variable n
and that it might be an actual variable (rather than a constant) later.
If so, please have a look at How to create a dynamic array of integers.
In short: You can create a pointer that points to the start of an array on the heap:
int* visited = new int[n];
which works just like you are used to with arrays, but must be freed with delete
in order to avoid leaking memory.
Better is using a container class that does this for you:
std::vector<int> visited(n);
Put any line in your code and it will work as intended.
As a general recommendation, you should read tutorials on how to work with the STL, including getting an overview over its container classes.