Jump to content

Math/division script won't work. . .


slpctrl

Recommended Posts

First off, here's the script:

 

<?php

$num = array();
For ($i = 1000; $i > 0; $i--){

if !($num/3) && || !($num/5)
{
$i--;
}
else{
array_push($num, $i);
echo "$i\n";
$i--;
}
}
echo array_sum($num);
?>

 

Now, what I'm trying to do is store every number under 1000 divisible by 3 or 5 into an array, and then add all the values in the array together; however, it doesn't work and I can't pinpoint where the error is. Any help is appreciated.

 

Edit: Also, I have the echo "$i\n"; in there to help with finding the error; it echoes nothing :\.

Link to comment
https://forums.phpfreaks.com/topic/175244-mathdivision-script-wont-work/
Share on other sites

if ((($num % 3) != 0) || (($num % 5) != 0))

 

 

Doesn't work; I've got it down to this:

 

<?php

$num = array();
For ($i = 1000; $i > 0; $i--){

if ((($num % 3) != 0) || (($num % 5) != 0))
{
   array_push($num, $i);
}

echo array_sum($num);
?>

 

I would think that'd work; but it doesn't. I've tried it with % and with /, nothing. When I insert that line just in my code, and move the code around so that it works it just echoes 1000 twice. :\

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.