# how to convert bolean to int

• (2 Pages)
• 1
• 2

## 18 Replies - 602 Views - Last Post: 30 May 2019 - 08:27 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=416283&amp;s=cade56fc651fa6194018165a732055ee&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #16 g00se

• D.I.C Lover

Reputation: 3635
• Posts: 16,702
• Joined: 20-September 08

## Re: how to convert bolean to int

Posted 30 May 2019 - 07:30 AM

Quote

... and changed some lines to make it work.

so you haven't tested it

### #17 Atspulgs

Reputation: 100
• Posts: 537
• Joined: 29-July 09

## Re: how to convert bolean to int

Posted 30 May 2019 - 07:52 AM

You have been given the exact things you need to write here...

---
If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20, print Not Weird
---

```if( n % 2 == 1 )
//Its odd so print "Weird"
else if( n % 2 == 0 && n >= 2 && n <= 5)
//Its even   and its between 2 and 5 inclusively therefore print "Not Weird".
//...

```

So on and on...

Note that I exaggerated whats actually needed to match the text.
For example, you don't need to check for evens if you've already ruled out odds... so you can just check the ranges afterwards...
Of course you can just check for Weird cases only and print Not Weird in all the other cases... but I don't know how much you are allowed to fudge the tasks.

This post has been edited by Atspulgs: 30 May 2019 - 07:53 AM

### #18 NormR

• D.I.C Lover

Reputation: 775
• Posts: 5,836
• Joined: 25-December 13

## Re: how to convert bolean to int

Posted 30 May 2019 - 08:04 AM

What is to be printed for numbers not in the selected ranges? EG 0 and < 0?

### #19 astonecipher

• Senior Systems Engineer

Reputation: 2876
• Posts: 11,252
• Joined: 03-December 12

## Re: how to convert bolean to int

Posted 30 May 2019 - 08:27 AM

```if(N >= 6 && N <= 20) {
```

That isn't necessary. Running a code sample,

Quote

1 Weird
2 Not Weird
3 Weird
4 Not Weird
5 Weird
6 Weird
7 Weird
8 Weird
9 Weird
10 Weird
11 Weird
12 Weird
13 Weird
14 Weird
15 Weird
16 Weird
17 Weird
18 Weird
19 Weird
20 Weird
21 Weird
22 Not Weird
23 Weird
24 Not Weird
25 Weird

Only 2 and 4 meet the criteria, because it is even only, 2-5 is irrelevant as is 6-20.