# Maths question

## Recommended Posts

A CD can hold upto 200 images

I need to know what formula to use to work out the quantity of CD's

If \$images = 0 then there would be 0 CD

If \$images = 12 then there would be 1 CD

If \$images =201 then there would be 2 CD's

I have this

```\$images = 12
\$maxCD = 200
Msgbox(0,"",Int(\$images/\$maxCD +1))```

Which works fine except for \$images = 0 because you still get 1 cd.

Am I better changing the code so that if \$images = 0 then \$CD = 0 or is there a better way

```\$images = 12
\$maxCD = 200

If \$images >  0 then

\$CD = Int(\$images/\$maxCD +1)
Else
\$CD = 0
EndIf```

Just need someone to confirm I'm right or an Arse

##### Share on other sites

That was fun...

```\$maxCD = 200
While 1
\$images = InputBox("CD Count", "How many images?")
If @error Then Exit

\$CDs = Int(\$images / \$maxCD)
If Mod(\$images, \$maxCD) Then \$CDs += 1
MsgBox(64, "Results", "At " & \$maxCD & " images per CD, it will take " & \$CDs & " CDs to hold " & \$images & " images.")
WEnd```

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

Take a look at the Ceiling function

Edit: well if you're give him code i'll do it too

```\$images = 12
\$maxCD = 200
Msgbox(0,"",Ceiling(\$images/\$maxCD))```
Edited by the_lord_mephy

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

##### Share on other sites

Take a look at the Ceiling function

Edit: well if you're give him code i'll do it too

```\$images = 12
\$maxCD = 200
Msgbox(0,"",Ceiling(\$images/\$maxCD))```
Ooh... I like! Never noticed that function before and had to go look it up!

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

Thanks both

Never heard of Ceiling() before.

## Create an account

Register a new account

×

• Wiki

• Back

• Git