Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 6.20 Factors
- Deitel & Deitel C++ How to Program, 10th ed(Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include < iostream>
- #include <cmath>
- using namespace std;
- bool isFactor(int testNum, int possibleFactor ) {
- if (testNum % possibleFactor == 0) return true;
- else return false;
- }
- int main() {
- while (true) {
- int someInt, someFactor;
- cout << "Enter a number and then enter a possible factor (or enter a 0 to end): ";
- cin >> someInt;
- if (someInt == 0) break;
- cin >> someFactor;
- if (someFactor == 0) break;
- cout << "You entered " << someInt << " and you wish to test if " << someFactor << " is a factor." << endl;
- cout << "Result: ";
- if (isFactor(someInt, someFactor)) cout << "true, " << someFactor << " is a factor of " << someInt << endl;
- else cout << "false, " << "Sorry, " << someFactor << " is not a factor of " << someInt << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment