### (SOLVED)Divisible Help

Help with this, I dont know whats going wrong it just says YES YES YES YES (school homework)

#include <iostream>

using namespace std;

int main()
{int n;
cout<<"n=";
cin>>n;
if (1>n>1000)
{
cout<<"Incorecct Value!";
}

if (n/2)
{cout<<"YES ";}
else
{cout<<"NO ";};

if (n/3)
{cout<<"YES ";}
else
{cout<<"NO ";};

if (n/5)
{cout<<"YES ";}
else
{cout<<"NO ";};

if (n/10)
{cout<<"YES ";}
else
{cout<<"NO ";};

return 0;
}
Last edited on
OK, please use code tags not output tag on code. (and your output tag failed)

if (1>n>1000) this looks very wrong...
how can n be more than a thousand yet less than 1??
I think what you want is use the OR like this,
if (n < 1 || n > 1000)
{
cout << "Incorrect Value";
return 0;
}

The reason it outputs:
 ` YES YES YES`

is probably because n/2 is a non zero value with zero representing false. If you enter bellow 10 but above 1 you probably will get atleast 1 NO.
But seriously what the hell is this program for?
It is a school homework...
I get now like n=5
YES YES YES NO
so for bigger or equal i get YES...
What is the homework? What is it suppose to say? Why do you include <iostream> twice, you only need to do it once... I want to help but please try to be more specific.
Last edited on
YES if it is divisible with 2,then 3 then 5 then 10
and if it isnt it must say NO
Oh, i get what you want now, there is something called modulus(%).
You use it to get the remainder example:
4%3 = 1 because that is the remainder. If the remainder is 0 you know it can be divided without leftovers. So you would have to change your if statements

if(n % 2 == 0)
cout << "yes";
else
cout << "nope";

try to change your if statements and it will work.
It is working now.Thanks!
Topic archived. No new replies allowed.