How to fix code?
the code says it didn't work because it needed an identifier. How do I fix it??
Voters
mwilki7 (1136)
I would recommend indenting your code in certain places, it may help spot errors.
I think you want to use the AND(&&
) operator: else if (a % 3 == 0 && a < 20)
if you want to have multiple conditions in a single if statement.
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Input a number ";
cin >> a;
if(a%5== 0)
cout <<"Yes";
else if (a%3== 0)(a<20);
cout << "Yes";
return 0;
}
The problem is with the parentheses
else if (a%3== 0)(a<20);
cout << "Yes";
What's really happening is this
else if (a % 3 == 0)
{
(a<20); // nothing really happens here
}
cout << "Yes";
IvanChang111 (12)
It works perfectly fine to me, It doesn't show any errors when I run it.
Hello. That is a warning. You can ignore warnings. During build-time, the compiler is just saying that you have some code that isn't being used or can be improved. Anyways, in your case, this is what is actually happening:
Perhaps you mean: