Advertisement
aaronvan

Untitled

Jan 29th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. string factors56(int n) {
  2.     if (n % 5 == 0 && n % 6 == 0) {
  3.         return n + " is divisible by both 5 and 6";
  4.     }
  5.     else if (n % 5 != 0 && n % 6 != 0) {
  6.         return n + " is not divisible by either 5 or 6";
  7.     }
  8.     else if ((n % 5 == 0 || n % 6 == 0) && !(n % 5 == 0 && n % 6 == 0)) {
  9.         return n + " is divisible by 5 or 6, but not both";
  10.     }
  11. }
  12.  
  13. // test code:
  14.     cout << (factors56(10) == "10 is divisible by 5 or 6, but not both" ? "Success" : "Fail")
  15.         << " on factors56 test 1" << endl;
  16.     cout << (factors56(30) == "30 is divisible by both 5 and 6" ? "Success" : "Fail")
  17.         << " on factors56 test 2" << endl;
  18.     cout << (factors56(23) == "23 is not divisible by either 5 or 6" ? "Success" : "Fail")
  19.         << " on factors56 test 3" << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement