Bug help
My teacher gave me a task: On a sidewalk there a n people. Some of them are walking right, someone are walking left. Those who go left are no 2,those who go right are number 1. When there are 1 and 2 one to other they are swapping. How many teleportations will be made while there are 1 and 2 one to other? My code: #include <bits/stdc++.h> using namespace std; bool teleportirana(int arr[]) { bool isit = false; for(int i=0; i<sizeof(arr)-1; i++) { if(arr[i] == 1 && arr[i+1] == 2) { isit = true; break; } } return isit; } int main() { int n; cin>>n; int arr[n]; for(int i=0; i<n; i++) { int a; cin>>a; arr[i] = a; } int count = 0; while(teleportirana(arr)) { for(int i=0; i<n-1; i++) { if(arr[i] == 1 && arr[i+1] == 2) { arr[i] = 2; arr[i+1] = 1; count++; } } } cout<<count; return 0; }