# Thread: I cant figure the problem out!

1. ## I cant figure the problem out!

Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true) if the second is a multiple of the first, and 0 (false) otherwise. Use this function in a program that inputs a series of pairs of integers.

I dont know what I need to do to fix this!

Code:
```#include <stdio.h>

int multiple(int x, int y, int a);

int main() {

int x;
int y;
int m;
int a;

printf("Enter first integer here:");
scanf("%d", &x);

printf("Enter second integer here:");
scanf("%d", &y);

m = multiple(x,y,a);

printf("%d is a multiple of the %d\n", m, m);

return 0;

}

int multiple(int x, int y, int a) {

a = x % y;

if(a == 0){
printf("%d is a multiple of the %d\n", y, x);
return 1;
else(a != 0);
printf("%d is not a multiple of the %d\n", y, x);
return 0;
}

}```

2. you're else statement is incorrect
Code:
``` int multiple(int x, int y, int a) {

a = x % y;

if(a == 0){
printf("%d is a multiple of the %d\n", y, x);
return 1;
}else{
printf("%d is not a multiple of the %d\n", y, x);
return 0;
}

}```
you should initialize a inside the subroutine instead of passing it down btw

3. Originally Posted by jturner38
Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return 1 (true) if the second is a multiple of the first, and 0 (false) otherwise. Use this function in a program that inputs a series of pairs of integers.

I dont know what I need to do to fix this!

Code:
```#include <stdio.h>

int multiple(int x, int y);

int main() {

int x;
int y;

printf("Enter the larger integer:");
scanf("%d", &x);

printf("Enter smaller integer here:");
scanf("%d", &y);

if(multiple(x,y))
printf("%d is not a multiple of %d\n", x, y);
else
printf("%d is a multiple of %d\n", x, y);

return 0;
}

int multiple(int x, int y) {

return (x % y);

}```

One problem was the semi-colon at the end of your
if (statement) {
//line of code here
//line of code here
} //where the curly brace for the if lines of code should go
else;
//this code never executes because of the semi-colon which
//ended the line of code for the compiler.

}//where the curly brace ONLY for the else lines of code, should go.

You misplaced the curly brace from before the else statement, to after it.

The above code may have it's own errors, as I haven't run it, but it will be very close.

4. Yea it did have errors! I set multiple(x,y) to variable m. Then had if m is not equal to 0 then print it is not a multiple. Its not printing when numbers are multiples.

Code:
```#include <stdio.h>

int multiple(int x, int y);

int main() {

int x;
int y;
int m;

printf("Enter smaller integer here:");
scanf("%d", &x);

printf("Enter larger integer here:");
scanf("%d", &y);

m = multiple(x,y);

if(m == 0)
printf("%d is a multiple of %d\n", x, y);
else
printf("%d is not a multiple of %d\n", x, y);

return 0;
}

int multiple(int x, int y) {

return (x % y);
}```

5. You want to find if the second number is a multiple of the first number....then you have to check your multiple(int x, int y) function on your return statement. It's backward. That's not the only thing that is backwards, look at the variables on your printf statements within your if/else statements.

6. ## Replace else ---> else if

Originally Posted by peeweearies
You want to find if the second number is a multiple of the first number....then you have to check your multiple(int x, int y) function on your return statement. It's backward. That's not the only thing that is backwards, look at the variables on your printf statements within your if/else statements.
There are couple of mistakes in your code:-

1. Don't use condition for both if and else
if you want check multiple condition better to use if and else if combination.

2. you trying to display the result in both main and subfunction.
i don't see any usage of such kind of code.
better you can display result either in main or subfunction.