trouble with sub/add negation function

I'm having trouble with the negation part of this Write a function that accepts two input parameters,computes the difference of those inputs by subtraction, and returns the result. You are NOT allowed to use the subtraction operator (−) . You are, however,allowed to use negation(−y) You must produce the final answer by calling the addition function that you wrote as part of the first problem. Any help would be appreciated

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


double subtraction(double a, double b);

int main()
{
	double num1;	//to store first number
	double num2;	//to store second number
	double sum;	    //to store addition 

	//read numbers
	cout << "Enter first number: ";
	cin >> num1;
	cout << "Enter second number: ";
	cin >> num2;

	//call function
	addition(num1, num2);

	//print addition
	cout << "The difference of " << num1 << " and " << num2 << " is: " << sum << endl;

	system("pause");
	return 0;
}

//function definition
double addition(double a, double b)
{
	return (a + b);
}
  
This is a basic maths question.

a + + b = a + b

a + - b = a - b
a - + b = a - b

a - - b = a + b

One of these identities ought to help you.
When you do something like: A - B, that's the same as A + (-B) - and you can just that in your function.
Thanks Guys Got it! Appreciate the help
Topic archived. No new replies allowed.