void divideWithRemainder(int a, int b, int& q, int&r){
q = a/b; //quotient of integers
r = a%b; //remainder
}
int main(){
cout << divideWithRemainder(10, 3) << endl;
return 0;
}
this will not produce anything because it says not enough arguments. however i attempted to add an "int q" and "int r" into my main functions and pass those to no avail. Can anyone provide some assistance on this?
Well you can't cout it to begin with, because it's a void function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
void divideWithRemainder(int a, int b, int& q, int&r){
q = a/b; //quotient of integers
r = a%b; //remainder
}
int main(){
int q, r;
divideWithRemainder(10, 3, q, r);
cout << q << "," << r << endl;
return 0;
}
By the way, cstdlib has the div() function that computes both the remainder and quotient. It may be faster than doing them separately because it can use a CPU instruction that does them both. http://www.cplusplus.com/reference/cstdlib/div/