please tell why aint the else condition executed and what possibles errors could be in the code
#include
using namespace std;
//total numbers of digits (count-1);
int Less(int n,int count)
{
int ans=0;
for(int i=1;i<count;i++)
{
ans=ans+(1<<i);
}
return ans;
}
//total numbers of (count) digit numbers below n
int Digit(int n,int count)
{
int ans2=0,t,p=1;
while(n!=0)
{
t=n%10;
if(t==7)
{
ans2=ans2 + p;
p=p2;
n=n/10;
}
else if(t==4)
{
p=p2;
n=n/10;
}
}
return ans2;
}
int main() {
int n;
cin>>n;
int count = 0;
int temp=n;
//digits with lucky number
while(temp!=0)
{
if(temp%10==4 || temp%10 == 7)
{temp=temp/10;
count++;}
}
//total number of digits
int count1=0,temp1=n;
while(temp1!=0)
{
temp1=temp1/10;
count1++;
}
//if count=count1 that means all digits are lucky numbers
if(count==count1)
{
int ans1=Less(n,count);
int ans2=Digit(n,count);
int ans=ans1+ans2;
cout<<ans;
}
else
cout<<"error";
return 0;
}