Hi everyone. My code is used to calculate fractions and display them as "3/4 + 3/4 = 3/2" and such. I having some trouble with the the code segment

calculate.setadd();
	calculate.setsub();
	calculate.setmult();
	calculate.setdiv();

There's a red line under the close parenthesis saying "too few arguments in function to call".

I don't get what's wrong, I'm doing it the same way as I'm doing in the book. I'm assuming its because the input for CIN somehow didn't go into num1, num2, den1, den2 but it has an error so it wouldn't debug for me to try.

Here's the rest of the code.

#include <iostream>
using namespace std;

class fraction
{
public:
    int getfraction(int, int, int, int);
	void setadd(int num1, int den1, int num2, int den2);
	void setsub(int num1, int den1, int num2, int den2);
	void setmult(int num1, int den1, int num2, int den2);
	void setdiv(int num1, int den1, int num2, int den2);
	void simplify1();
	void simplify2();
private:
    int numerator1;
	int numerator2;
	int denominator1;
	int denominator2;
};

void fraction::simplify1()
{
	
}

void fraction::simplify2()
{

}

void fraction::setadd(int num1, int den1, int num2, int den2)
{
	
	cout << num1 << "/" << den1 << "+" << num2 << "/" << den2 << endl;
}

void fraction::setsub(int num1, int den1, int num2, int den2)
{
	
	cout << num1 << "/" << den1 << "-" << num2 << "/" << den2 << endl;
}

void fraction::setmult(int num1, int den1, int num2, int den2)
{
	
	cout << num1 << "/" << den1 << "*" << num2 << "/" << den2 << endl;
}

void fraction::setdiv(int num1, int den1, int num2, int den2)
{
	
	cout << num1 << "/" << den1 << "/" << num2 << "/" << den2 << endl;
}

int main()
{
    fraction calculate;
    int num1;
    int den1;
    int num2;
    int den2;
    cout << "This program does some fraction math" << endl;
    cin >> num1 >> den1 >> num2 >> den2;
	
	calculate.setadd();
	calculate.setsub();
	calculate.setmult();
	calculate.setdiv();

    if (num1 == 0)
        cout << "Don't use 0." << endl;

    if (num2 == 0)
        cout << "Don't use 0." << endl;

    if (den1 == 0)
        cout << "Don't use 0." << endl;

    if (den2 == 0)
        cout << "Don't use 0." << endl;

    system("pause");
    return 0;
}

*The code is still incomplete but I just can't get this part.

Edited 5 Years Ago by visom: n/a

Let's take a look at the function setadd.

void fraction::setadd(int num1, int den1, int num2, int den2)

There it is. It takes one, two, three, four integer parameters. That means that when we call this function, we must give it four arguments, which must all be of type int. Something like this;

fraction calculate;
 int num1;
 int den1;
 int num2;
 int den2;
 calculate.setadd(num1, den1, num2, den2);

On the last line there, we call the function with four int parameters.

You called the function like this:

calculate.setadd();

You gave it zero arguments, when it requires four. You gave it too few arguments, hence the error you're getting: "too few arguments in function to call".

Thank you so much moschops! Can't believe I'm stuck on something so easy;...

This question has already been answered. Start a new discussion instead.