-
Help please.
I have this project from school that has me program a code to tell the user if a given number is lucky or not. The number is lucky if it is a factor of 7, 11, or ends with a 7. I can do the first two parts but the last i dont get (ends in 7 part). Any help would be awsome.
Thanks
-
Try using the % operator.
--
Mats
-
convert it to a string and check the last character.
-
The % (modulus) operator is cleaner. Or more efficient anyway.
Code:
if(number % 10 == 7) {
std::cout << "number ends with a 7.\n";
}