garryhtreez

6.20

Dec 9th, 2020
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. /* 6.20 Factors
  2.         Deitel & Deitel C++ How to Program, 10th ed(Indian subcontinent adaptation)
  3.         Visual Studio Community 2019
  4. */
  5.  
  6. #include < iostream>
  7. #include <cmath>
  8. using namespace std;
  9.  
  10. bool isFactor(int testNum, int possibleFactor ) {
  11.     if (testNum % possibleFactor == 0) return true;
  12.     else return false;
  13. }
  14.  
  15. int main() {
  16.     while (true) {
  17.         int someInt, someFactor;
  18.         cout << "Enter a number and then enter a possible factor (or enter a 0 to end): ";
  19.         cin >> someInt;
  20.         if (someInt == 0) break;
  21.         cin >> someFactor;
  22.         if (someFactor == 0) break;
  23.         cout << "You entered " << someInt << " and you wish to test if " << someFactor << " is a factor." << endl;
  24.         cout << "Result: ";
  25.         if (isFactor(someInt, someFactor)) cout << "true, " << someFactor << " is a factor of " << someInt << endl;
  26.             else cout << "false, " << "Sorry, " << someFactor << " is not a factor of " << someInt << endl;
  27.     }
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment