0

When I input for example 10 and 4 it just return 2.00 instead of 2.50.

here is my function call in the main:

printf("\nQuotient = %.2f", quot(num1, num2));

Here is my user defined function that computes the quotient of two numbers x and y:

float quot(int x, int y){
    float quotient;
    if(x > y){
        quotient = x / y;
    }
    else{
        quotient = y / x;
    }
    return quotient;
}
273K
  • 29,503
  • 10
  • 41
  • 64
Minju
  • 1
  • 2
  • the code seemed to be cut for some reason but that is the start below the function name – Minju Mar 22 '22 at 06:25
  • First division in integer 10/4 = 2, Then convert to float 2.0. – Mike Mar 22 '22 at 06:29
  • so thats why its returning .00 because the inputted numbers are integers? 5/2=2 which is 2.0 but if I were to input 5.0 / 2.0 its gonna be 2.5 ? – Minju Mar 22 '22 at 06:31
  • Cast the ints to floats and should work as expected: `quotient = (float)x / (float)y` and `quotient = (float)y / (float)x` – Jeshua Lacock Mar 22 '22 at 06:41

0 Answers0