# Thread: help with fraction division function

1. ## help with fraction division function

i am working on a fraction calculator using functions and i'm stuck. when i compile my code i get an error that says function fracDiv cannot take 0 parameters... can anyone help? here's my code so far:

Code:
```#include <iostream>

using namespace std;

//Function prototype: fracDiv
//--------------------------------------------------------------------
// Function:       fracDiv
// Purpose:        Divide two fractions and receive the output as a fraction
//   a/b / c/d = (a*d) / (b*c)
// Preconditions:  parameters: a (int, numerator of first fraction, value parameter)
//   b (int, denominator of first fraction, value parameter)
//   c (int, numerator of second fraction, value parameter)
//   d (int, denominator of second fraction, value parameter)
//   num (int, numerator of result, reference parameter)
//   den (int, denominator of result, reference parameter)
//
// Postconditions: Returns: int--0 if calculation can be performed,
// 1 if denominator of first fraction is zero
// 2 if denominator of second fraction is zero
// 3 if numerator of second fraction is zero
//   num contains numerator of result
//   den contains denominator of result
//
int fracDiv(int a, int b, int c, int d, int& num, int& den);

int main()
{
int numerator, denominator;
int a = 0;
int b = 0;
int c = 0;
int d = 0;

cout << "Enter two fractions: " << endl;
cin >> a >> b >> c >> d;

fracDiv(numerator, denominator);

cout << "Answer = " << numerator << "/" << denominator << endl;

return 0;
}

//Function
int fracDiv(int a, int b, int c, int d, int& num, int& den)
{

num = a * d;
den = b * c;

return 0;

}```

2. move:
Code:
```int fracDiv(int a, int b, int c, int d, int& num, int& den)
{

num = a * d;
den = b * c;

return 0;

}```
to the area above:
Code:
`int fracDiv(int a, int b, int c, int d, int& num, int& den);`
and see if that helps.

3. You should call your function like this:
Code:
`fracDiv(a,b,c,d,numerator, denominator);`
Originally Posted by 7smurfs
move:
to the area above:
and see if that helps.
How on earth would that change anything?

4. I thought you couldn't call a function before it was made?

5. Yes you can, that's the purpose of the declaration of the function name at the beginning.

6. Call me dumb, but wouldn't this be a problem?
int fracDiv(int a, int b, int c, int d, int& num, int& den);
defines fracDiv to take a, b, c, d, num, den

fracDiv(numerator, denominator);
calls fracDiv, but it only takes in 2 parameters instead of 6

That said, I'm a newb

7. problem solved, i was just being stupid and i put the types in the function call.