Decimal to octal

#include
#include
using namespace std;
int power(int a,int b){
int c=1;
if(b==0) return c;
for(int i=1;i<=b;i++){
c*=a;
}
return c;
}
int main() {
int n;
cin>>n;
vector a;
int i=0,sum=0;
while(n>0){
int digits;
if(i==0) digits=n%8;
else digits=n/(power(8,i));
a.push_back(digits);
n=n-(digits*(power(8,i)));
i++;
}
int s=a.size();
for(int j=s-1;j>=0;j–){

	sum=sum*10+a[j];
	
}
cout<<sum<<endl;

return 0;

}
Why some test cases fail;