I am trying to check if a number is in an array in C++. The solution I have is kinda messy:
int luckynumbers[5] = { 3, 5, 8, 15, 19};
std::cout << "Enter number from 1 - 20: ";
int choice;
std::cin >> choice;
if (choice == luckynumbers[0] || luckynumbers[1] || luckynumbers[2] || luckynumbers[3] || luckynumbers[4])
{
std::cout << "You are lucky!";
}
Anyone has any tips/better practice ways to write the if
statement part?