The user enters the dividend and the divisor and the program has to return the quotient through a function that does subtraction. It gives me the following error: It is really a problem that the program does not perform instead of a syntax problem
Failed example:
printf '20 100' | ./program
Expected:
0
Got:
20
**********************************************************************
File "", line 5, in __main__
Failed example:
printf '100 20' | ./program
Expected:
5
Got:
0
I attach the code:
#include <iostream>
using namespace std;
int division(int a, int b);
int main(){
int a, b;
cin >> a >> b;
cout << division(a, b);
}
int division(int a, int b){
int temporal=a;
for(int i=0; a>=b; i++){
if ((temporal - b)<=0){
temporal -= 4;
}
return i;
}
}
Here is a possible solution to your doubt using a
while()
:For this example the following numbers have been taken:
This answer is based on the following link