viewing paste Division by Subtraction in C++ | C++

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <iostream>
using namespace std;
 
int main() {
        int numerator, denominator, quotient;
 
        cout << "Input the number you would like to divide: ";
        cin >> numerator;
       
        cout << "Input the number you would like to divide " << numerator << " by: ";
        cin >> denominator;
 
        int remainder = numerator;
 
        for (quotient = 1; remainder >= denominator; quotient++) {
                remainder -= denominator;
        }
 
        cout << numerator << " divided by " << denominator << " equals " << quotient;
 
        if (remainder) {
                cout << " with a remainder of " << remainder;
        }
       
        cout << "." << endl;
}
Viewed 474 times, submitted by datmumbles.