#include <iostream>
#include <vector>
bool is_lucky(int check_num)
{
while(check_num!=0)
{
if((check_num%10!=4)&&(check_num%10!=7))
{
return false;
}
check_num/=10;
}
return true;
}
int main()
{
std::vector <long long> lucky;
for(int in_num=1;in_num<1000;in_num++)
{
if(is_lucky(in_num))
{
lucky.push_back(in_num);
}
}
}
Even though I am still using the for-if anti-pattern as Deduplicator pointed out, I was finally able to make the is_lucky function which maybe less efficient and a lesser intelligent way to do it than the other ones posted, seems to be the shortest way to do the task.