Using Func. to determine if b is multiple of a. Must use return void.

Hello,
Why wont this compile? I'm lost. Please help.

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
 #include <iostream>

using namespace std;

void FindMultiple(int &, int &);

int main()
{
	int a=2, b=68;
	cout << "Enter the that divisor, then the number to be divided: ";
	cin >> a >> b;
	
	if (FindMultiple(a, b) == 0);
	{
		cout << a << " is a mulitple of " << b << "!"
	}
	else
	{
		cout << a << " and " << b << " are not multiples of each other.";
	}

	system("pause");

	return 0;
 }

 void FindMultiple(int &n1, int &n2)
{
	 
	 n2%n1;
	
	 return;

}
if (FindMultiple(a, b) == 0);

The code expects the FindMultiple function to return a boolean value here to compare with 0, but it's a void function.

Also - remove the semicolon at the end of that if line.


Line 30 - this calculates a value, but it doesn't get stored anywhere.
This is the updated code. Does the job. Thanks Wildblue.

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
#include <iostream>

using namespace std;

void FindMultiple()
{
	int n1, n2;
	cout << "Enter n1: ";
	cin >> n1;
	cout << "enter n2: ";
	cin >> n2;

	if (n2%n1 == 0)
	{
		cout << n2 << " is a multiple of " << n1 << endl;
	}

	else

	return;

}


int main()
{

	FindMultiple();
	
	
	system("pause");

	return 0;
 }

 


Topic archived. No new replies allowed.