Trouble with defined function (error c2660)

I am trying to make a fraction calculator but keep getting error c2660. I am not sure if it is a logic problem or my function is not well defined. I tried googling and it says is that my function does not match. I am not sure what to do and any help is greatly appreciate, thanks in advance.

"Error 4 error C2660: 'calculate' : function does not take 0 arguments c:\users\users\onedrive\documents\cpp program\exercises\problem 3\problem 3\Practice.cpp 41 1 problem 3"


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
using namespace std;

// function declaration
	bool validDenominator(int);
	void readFrac(int num &, int denom &);
	void readOp(char&);
	void printFrac(int fract1, int fract2);
	void calculate (int fract1, int fract2, char Op, int ans, int, int &, int&);
	bool doubleValue(int, int, double &);

// main program
int main()
{

	cout << "This program will help you calculator two fraction.";


		int numerator, denominator;
		
		cout << "Please enter your first numerator: ";
		cin >> numerator;
		cout << endl;
		cout << "Please enter your first denominator: ";
		cin >> denominator;	
		cout << endl;
		
		while (validDenominator(denominator) == true)
		{

		readFrac();
		readOp();
		calculate();
		printFrac();

		}
	return 0;
}

bool validDenominator(int denominator) // check if num/den are valid
{
	if (validDenominator > 0)
	{
		cout << "It is not a valid denominator, please try again.";
	}
}

void readFract(int num , int denom ) //prompt for fraction
{
	
	cout << "Please enter your first fraction in term of numerator and denominator followed by a [space] key."
		<< "eg: 4 [space] 5 is equal to 4/5. " << endl;
	cin >> num, denom;

	cout << "Please enter your second fraction." << endl;
	cin >> num, denom;
}

void readOp(char Op &) // prompt for operator (+, - , * , / ) and check if valid
{
	cout << "Please enter an operator to perform a calculatoion such as ( '+', '-', '*', '/' ) :" << endl;
	cin >> Op;
}

void printFrac(int fract1, int fract2 ) //display the final answers
{
	char Op;
	double ans;
	cout << fract1 << ", " << Op << ", "<< fract2<< ", "<< ans;
}
void calculate(int fract1, int fract2, char Op, int ans, int, int &, int&) // calculate the request operation
{
	switch (Op)
	{
	case '+': ans = fract1 + fract2;
		break;   // addition
	case '-': ans = fract1 - fract2;
		break;	// substraction
	case '*': ans = fract1*fract2;
		break;	// multiplication
	case '/': ans = fract1 / fract2;
		break;	// division
	default: cout << "Your input is invalid, please try again.";
	}
}
bool doubleValue(int, int, double &); //if fraction is valid, assign the fraction to double if not return false
{

}






Hi,

Just as the compiler says, you call the function on line 33 with no arguments, it was expecting 7 arguments.

You also need to provide names for the parameters on line 71. I like to do that for the declaration of the function as well.

Line 42 , you probably meant denominator not the name of the function.

The readFract function achieves nothing, the parameters need to be references.

The calculate function does not calculate fractions: an int is not a fraction; integer division does not work.

There you go some things to work on :+)


6:24: error: expected ',' or '...' before '&' token
In function 'int main()':
31:12: error: too few arguments to function 'void readFrac(int)'
6:7: note: declared here
32:10: error: too few arguments to function 'void readOp(char&)'
7:7: note: declared here
33:13: error: too few arguments to function 'void calculate(int, int, char, int, int, int&, int&)'
9:7: note: declared here
34:13: error: too few arguments to function 'void printFrac(int, int)'
8:7: note: declared here In function 'bool validDenominator(int)':
42:25: warning: ordered comparison of pointer with integer zero [-Wextra]
46:1: warning: no return statement in function returning non-void [-Wreturn-type]
At global scope:
40:27: warning: unused parameter 'denominator' [-Wunused-parameter] In function 'void readFract(int, int)': 53:19: warning: right operand of comma operator has no effect [-Wunused-value]
56:19: warning: right operand of comma operator has no effect [-Wunused-value]
At global scope:
59:21: error: expected ',' or '...' before '&' token
87:1: error: expected unqualified-id before '{' token
Topic archived. No new replies allowed.