My programs does its function when both numbers are positive but when one of them is negative it does not.
Program objective: Write a program that reads an integer number a and a natural number b, with b > 0, and prints the integer division d and the remainder r of a divided by b.
Remember that, by definition, d i r must be the only integer numbers such that 0 ≤ r < b and d · b + r = a.
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
using namespace std;
int main(){
int a,b;
b > 0;
cin >> a >> b;
int d = a/b;
int r = a%b;
cout << d << " " << r << endl;
}
|
In my program:
32/6 = 5 2 (division and remainder)
-32/6 = -5 -2 (division and remainder)
What program is supposed to do:
32/6 = 5 2 (division and remainder)
-32/6 = -6 4 (division and remainder)
Tell me step by step and why you do that, thanks