garryhtreez

6.24

Dec 9th, 2020
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. /* 6.24 Separating Digits
  2.    Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.    Visual Studio Community 2019
  4. */
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int getQuotient(int dividend, int divisor) {
  9.       return dividend / divisor;
  10. }
  11.  
  12. int getRemainder(int dividend, int divisor) {
  13.    return dividend % divisor;
  14. }
  15.  
  16. void indivDigits(int testNum) {
  17.    for (int divisor = 10000; divisor >= 10; divisor /= 10) {
  18.       if (testNum >= divisor) cout << getQuotient( testNum, divisor) << "  ";
  19.       testNum = getRemainder(testNum, divisor);
  20.    }
  21.    cout << testNum << endl << endl;
  22.    return;
  23. }
  24. int main() {
  25.    cout << "Enter a dividend followed by a divisor: ";
  26.    int dividend, divisor, quotient;
  27.    cin >> dividend >> divisor;
  28.  
  29.    quotient = getQuotient(dividend, divisor);
  30.    cout << "quotient is: " << quotient << endl;
  31.    cout << "The remainder, after division, is: " << getRemainder( dividend, divisor) << endl << endl;
  32.  
  33.    while (true) {
  34.       int testNum = 0;
  35.       cout << "Enter an integer from 1 to 32767 (inclusive) or enter 0 to end: ";
  36.       cin >> testNum;
  37.       if (testNum == 0) break;
  38.       cout << "Individual digits are as follows: ";
  39.       indivDigits(testNum);
  40.    }
  41.    return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment