Is there any other way I can get void smallest to have one output without changing void smaller?



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
#include <iostream>
using namespace std;

	void smaller (int a, int b) // return the smaller of a and b (if they are equal then just return that value)
	{
		cout << "Between the numbers: " << a << " and " << b << endl;

			if (a < b) // if a is less than b, then print a
			{
				cout << a << " is smaller." << endl;
			}
				else if (b < a) // if b is less than a, then print b
				{
					cout << b << " is smaller." << endl;
				}
					else //otherwise, if a is not smaller and b is not smaller, then print ...
					{
						cout << "The numbers have the same value." << endl;
					}
							cout << endl;
	}

	void bigger (int a, int b) // return the bigger of a and b (if they are equal then just return that value)
	{
		cout << "Between the numbers: " << a << " and " << b << endl;

			if (a > b) // if a is greater than b, then print a
			{
				cout << a << " is bigger." << endl;
			}
				else if (b > a) // if b is greater than a, then print b
				{
					cout << b << " is bigger." << endl;
				}
					else // otherwise, if a is not bigger and b is not bigger, then print ...
					{
						cout << "The numbers have the same value." << endl;
					} 
							cout << endl;
	}

	void smallest (int a, int b, int c) // return the smallest of a, b and c
	{
		smaller(a, b);
		smaller(a, c);
	}

	int main () 
	{
		smaller (1, 8);
		bigger (1, 8);
		smallest (100, 232, 3423);

			return 0;
	}
Last edited on
closed account (2UD8vCM9)
What exactly are you trying to do? All of your functions are void so none of them return anything so it's really confusing what your objective is.
Sorry, I should have just posted the whole code. I'm trying to return the smallest of the values in void (smallest), however, my void (smaller) can only compare which is the smallest between two integers (it must stay that way, bc of the rules of my assignment). As you can see in void (smallest), it tells me which is the smallest between the a and b, a and c. However, I want to find out which is the smallest between a, b, and c, using void (smaller) that compares only two integers.
closed account (2UD8vCM9)
Well none of your functions are returning anything, so you have to change the way they all work.

Your functions should be int and not void.

Here is an example of how your smaller function should look like.
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
#include <iostream>
using namespace std;

int smaller(int a, int b) // return the smaller of a and b (if they are equal then just return that value)
{
	if (a < b) // if a is less than b, then print a
	{
		return a; //return value of a
	}
	else // if b is less than a or if b is equal to a
	{
		return b; //return value of b
	}
}

int main()
{
	int num1 = 5;
	int num2 = 7;
	int smallernumber = smaller(num1, num2); //Take the smaller number between num1 and num2 and store it in smallernumber
	cout << "The first number is: " << num1 << endl;
	cout << "The second number is: " << num2 << endl;
	cout << "The smaller number is: " << smallernumber << endl;
	return 0;
}


Do you understand what you need to do now for your bigger/smallest functions?
Yes, thanks! That really helped a lot. Gave me a new way to think about it =)
Topic archived. No new replies allowed.