determine if the input integer is a multiple of 5 use a modulus

hi i am having a hard time with this program. i need to determine if the integer the user enters is a multiple of 5 or not with a modulus. this is what i got so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>

using namespace std;

int main()
  {
 int num1, num2;

 cout << "Enter an integer: ";
 cin >> num1;
 
 cout << "Enter a second integer:";
 cin >> num2;

 int num = 0;
 if (num % 5 == 0)
 cout << num1 << " is a multiple of " <<num2 << endl;
 }
 else
 (num % 5 != 0);
 cout << num1 << " is not a multiple of " <<num2 << endl;
{
 return 0;
 }


no matter what number i enter it does not work out and just repeats back to what was typed.
Last edited on
you have you braces in the wrong place.
Also..
i need to determine if the integer the user enters is a multiple of 5

so why ask the user for 2 numbers?
where do i move the brackets?
i took out the second one .

#include <iostream>

using namespace std;

int main()
{
int num1;

cout << "Enter an integer: ";
cin >> num1;


int num = 0;
if (num % 5 == 0)
cout << num1 << " is a multiple of " <<num1 << endl;
}
else
(num % 5 == 0);
cout << num1 << " is not a multiple of " <<num1<< endl;
{
return 0;
}
you don't need to create a 'num' variable:
int num = 0;

You need to test the number you read in (i.e. 'num1'):


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main()
{
	int num1;

	cout << "Enter an integer: ";
	cin >> num1;

	if (num1 % 5 == 0)
	{ 
		cout << num1 << " is a multiple of " << 5 << endl;
	}
	else
	{
		cout << num1 << " is not a multiple of " << 5 << endl;
	}
	return 0;
}
Thank you very much!
Topic archived. No new replies allowed.