Tavas and SaDDas

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=p
2;
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;

}

Please run your code on https://ide.codingblocks.com/ and share the link

@deepna Okay so your code had a few mistakes.
First one being that you need to store n in a dummy variable and then do the operations to find the number of digits in it. So I stored it in a variable k.
Now your code for the 2 functions was returning wrong answer , so I commented those two and replaced them with a much simpler function calc() and used a simple formula as I traverse from most significant digit to least significant digit. I converted the number to string , but you can do it the other way around as well.
Please take a look https://ide.codingblocks.com/s/196349
Feel free to ask if you have any further doubts.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.