Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string factors56(int n) {
- if (n % 5 == 0 && n % 6 == 0) {
- return n + " is divisible by both 5 and 6";
- }
- else if (n % 5 != 0 && n % 6 != 0) {
- return n + " is not divisible by either 5 or 6";
- }
- else if ((n % 5 == 0 || n % 6 == 0) && !(n % 5 == 0 && n % 6 == 0)) {
- return n + " is divisible by 5 or 6, but not both";
- }
- }
- // test code:
- cout << (factors56(10) == "10 is divisible by 5 or 6, but not both" ? "Success" : "Fail")
- << " on factors56 test 1" << endl;
- cout << (factors56(30) == "30 is divisible by both 5 and 6" ? "Success" : "Fail")
- << " on factors56 test 2" << endl;
- cout << (factors56(23) == "23 is not divisible by either 5 or 6" ? "Success" : "Fail")
- << " on factors56 test 3" << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement