Basic Functions

The question is : Create a functions which: sum two integers (when x>=y)or calculate a*b(x<y) - find maximum value of 2 integers

what should i do here? sorry im just a beginner i couldn't understand

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
#include <iostream>
using namespace std;
int max_value(int x, int y);
int sum_pr(int x, int y);
int main()
{
	int a, b, max, s;
	cout << "Input values\n";
	cout << "a=";
	cin >> a;
	cout << "b=";
	cin >> b;

	max = max_value(a, b);
	cout << max << "\n";
	s = sum_pr(a, b);
	cout << s << "\n";
	system("pause");
}

int sum_pr(int x, int y)
{
	if (x >= y)
	{
		//write a code...
	}
	else
	{
		//write a code...
	}
}

int max_value(int x, int y)
{
	if (x > y)
	{
		//write a code...
	}
	else
	{
		//write a code...
	}

}
Hello kerem59,

If I understand the directions:
1
2
3
4
5
6
7
8
9
10
11
12
13
int sum_pr(int x, int y)
{
    if (x >= y)
    {
	return x + y;
    }
    else
    {
	return x * y;
    }

    //return 0;  // <--- If your compiler gives you a warning.
}

Use the same idea for the other function.

Andy
1
2
3
4
int sum_pr(int x, int y)
{
	return x >= y ? x + y : x * y;
}


find maximum value of 2 integers


Use the std::max() function. See http://www.cplusplus.com/reference/algorithm/max/
Topic archived. No new replies allowed.