Math Problem

Thread Solved

Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Math Problem

 
0
  #1
Oct 4th, 2008
Okay, so I'm writing an application. In this application there is a drop down with the selections 10, 20, 30, and so on to 100. This drop down controls the amount of times a loop will occur. Basically, every time the application gets to a loop that is 10% of the total amount of loops, I want it to echo out a small line. On the user end this outputs a small block in a progress bar.

For example if you choose 10, then every loops it would output a block on the progress bar to give us 100%.

If you choose 20, every 2 loops it would output a block on the progress bar to give us 100%.

The easy way out would be to make a huge case select of if, elseif statement, but that's not what I want to do.

As an example, if you choose 10 ($amount = 10), it works correctly. $i is the increment of the loop.
  1. echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";

I know that's very confusing, but hopefully someone can understand and give me some mathematical help.
"We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." - Robert Wilensky
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,478
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Math Problem

 
1
  #2
Oct 4th, 2008
I have had to do similar things in the past and I find division and rounding to be the answer. An example is as below:
  1. $loop=0;
  2. while ($loop<=100)
  3. {
  4. $val=$loop/10;
  5. if ($val==round($val))
  6. {
  7. echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";
  8. }
  9. $loop+=1;
  10. }
Hope that helps to answer your question.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: Math Problem

 
0
  #3
Oct 4th, 2008
Well, your solution didn't work for me, but it got me thinking and now my code works.

Soon I'm going to post it in the Web Developer's Lounge. It'll be something everyone wants.
"We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." - Robert Wilensky
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Math Problem

 
0
  #4
Oct 4th, 2008
I don't know if round would be necessary since 10, 20, 30..., 100 are all % 10 evenly.

And I don't see why this code:
Originally Posted by MVied View Post
  1. echo ($i % ($amount / 10) == 0) ? "<div class=\"load\"></div>" : "";
wouldn't work.

Can you post the rest of your code?
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Math Problem

 
0
  #5
Oct 4th, 2008
Oh, you got it, OK.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: Math Problem

 
1
  #6
Oct 4th, 2008
Basically the problem was $i starting off as 0. This threw it off completely. I used $n to start as 1 and count (because I use the $i for more than just an increment).

I'll be posting this project soon. I know you'll like it R0b
Last edited by MVied; Oct 4th, 2008 at 11:13 pm.
"We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." - Robert Wilensky
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC