Using Conditional State create a division program

Using Conditional Statement create a program to find if the number is divisible by 2 (also 2 is multiplied by the divisor) and if the n is not divisible by 2 and lastly if the n is unable to divide.

example input/output:
Enter number: 24
24 is divisible by 2 ( 2 is multiplied by 12)

Enter number: 33
33 is not divisible by 2

Enter number: 0
unable to divide.

Can someone help me to create this program? thank you.
Last edited on
Can someone help me to create this program?

Well, what code have you written already? Post that using code tags.
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either

Or are you expecting US to do all the work of writing code for you, for free? Not. Gonna. Happen.
Making a start by writing some pseudocode is often a good move.

input an integer
if (the number is zero)
(
 then
    print 'unable to divide
 otherwise
    if(number is divisble by 2)
   (
      print 'the number is even'
      divisor = number divided by 2
      print 'number = divisor times 2'
   )
   otherwise
    print 'the number is not divisible by 2'
)
Can someone help me to create this program?


Yes. But I suspect you mean Will someone...

What part of this are you having difficulty with? What have you attempted so far - post your current code.

Using Conditional Statement create a program to find if the number is divisible by 2 (also 2 is multiplied by the divisor) and if the n is not divisible by 2 and lastly if the n is unable to divide.

example input/output:
Enter number: 24
24 is divisible by 2 ( 2 is multiplied by 12)

Enter number: 33
33 is not divisible by 2

Enter number: 0
unable to divide.

Can someone help me to create this program? thank you.


in c++ the % operator is the 'remainder' or 'modulo' operator.
33 % 2 is 1: 33 divided by two has a remainder of 1.
32 %2 is 0: 32 divided by two has a remainder of 0.

you may also consider &.
& is binary and. 001 & 1 is 1. 110 & 1 is 0. 33's one's bit (right most) is 1. 32's is zero. ...

if(x) //if true, its not zero.
you can also expliciticly say if (x==0) if you want.
Last edited on
Topic archived. No new replies allowed.