#include
using namespace std;
int
main ()
{
int multiple;
cout << "Please give a number you want to check the multiple of: ";
cin >> multiple;
if ((multiple % 5 == 0), (multiple % 2 == 0));
{
cout << multiple << " is multiple of five. " << endl;
cout << multiple << " is the multiple of two. ";
}
else {
cout << multiple << " is not multiple of five. " << endl;
cout << multiple << " is not the multiple of two. ";
}
return 0;
}
I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement. I can't find the error in the code. It shows error in the else statement.
CodePudding user response:
You have syntax errors in line
if ((multiple % 5 == 0), (multiple % 2 == 0));
^ ^
It should be
if ((multiple % 5 == 0) || (multiple % 2 == 0))
CodePudding user response:
It shows an error in the else statement because C doesn't regard your if statement. C ignores your 'if' because you ended it with a semi-colon (;). When C sees a ' ; ' your if-statement has no effect - it just skips it. Also, your if-syntax is wrong. It shouldn't have a comma ( , ).
This is what you intended to do:
if (multiple % 5 == 0 && multiple % 2 == 0) {
cout << multiple << " is a multiple of five. " << endl;
cout << multiple << " is a multiple of two. ";
}
else {
cout << multiple << " is not a multiple of five. " << endl;
cout << multiple << " is not a multiple of two. ";
}