Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: shorter code

  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    shorter code

    Is There Any Way To Short This Code ?

    Code:
    if ($speed <= 6){ $percentage1 = 1; }
    elseif ($speed <= 12){ $percentage1 = 2; }
    elseif ($speed <= 18){ $percentage1 = 3; }
    elseif ($speed <= 24){ $percentage1 = 4; }
    elseif ($speed <= 30){ $percentage1 = 5; }
    elseif ($speed <= 36){ $percentage1 = 6; }
    elseif ($speed <= 42){ $percentage1 = 7; }
    elseif ($speed <= 48){ $percentage1 = 8; }
    elseif ($speed <= 54){ $percentage1 = 9; }
    elseif ($speed <= 60){ $percentage1 = 10; }
    elseif ($speed <= 66){ $percentage1 = 11; }
    elseif ($speed <= 72){ $percentage1 = 12; }
    elseif ($speed <= 78){ $percentage1 = 13; }
    elseif ($speed <= 84){ $percentage1 = 14; }
    elseif ($speed <= 90){ $percentage1 = 15; }
    elseif ($speed <= 96){ $percentage1 = 16; }
    elseif ($speed <= 102){ $percentage1 = 17; }
    elseif ($speed <= 108){ $percentage1 = 18; }
    elseif ($speed <= 114){ $percentage1 = 19; }
    elseif ($speed <= 120){ $percentage1 = 20; }
    elseif ($speed <= 126){ $percentage1 = 21; }
    elseif ($speed <= 132){ $percentage1 = 22; }
    elseif ($speed <= 138){ $percentage1 = 23; }
    elseif ($speed <= 144){ $percentage1 = 24; }
    elseif ($speed <= 150){ $percentage1 = 25; }
    elseif ($speed <= 156){ $percentage1 = 26; }
    elseif ($speed <= 162){ $percentage1 = 27; }
    elseif ($speed <= 168){ $percentage1 = 28; }
    elseif ($speed <= 174){ $percentage1 = 29; }
    elseif ($speed <= 180){ $percentage1 = 30; }
    elseif ($speed <= 186){ $percentage1 = 31; }
    elseif ($speed <= 192){ $percentage1 = 32; }
    elseif ($speed <= 198){ $percentage1 = 33; }
    elseif ($speed <= 204){ $percentage1 = 34; }
    elseif ($speed <= 210){ $percentage1 = 35; }
    elseif ($speed <= 216){ $percentage1 = 36; }
    elseif ($speed <= 222){ $percentage1 = 37; }
    elseif ($speed <= 228){ $percentage1 = 38; }
    elseif ($speed <= 234){ $percentage1 = 39; }
    elseif ($speed <= 240){ $percentage1 = 40; }
    elseif ($speed <= 246){ $percentage1 = 41; }
    elseif ($speed <= 252){ $percentage1 = 42; }
    elseif ($speed <= 258){ $percentage1 = 43; }
    elseif ($speed <= 264){ $percentage1 = 44; }
    elseif ($speed <= 270){ $percentage1 = 45; }
    elseif ($speed <= 276){ $percentage1 = 46; }
    elseif ($speed <= 282){ $percentage1 = 47; }
    elseif ($speed <= 288){ $percentage1 = 48; }
    elseif ($speed <= 294){ $percentage1 = 49; }
    elseif ($speed <= 300){ $percentage1 = 50; }
    elseif ($speed <= 306){ $percentage1 = 51; }
    elseif ($speed <= 312){ $percentage1 = 52; }
    elseif ($speed <= 318){ $percentage1 = 53; }
    elseif ($speed <= 324){ $percentage1 = 54; }
    elseif ($speed <= 320){ $percentage1 = 55; }
    elseif ($speed <= 326){ $percentage1 = 56; }
    elseif ($speed <= 332){ $percentage1 = 57; }
    elseif ($speed <= 338){ $percentage1 = 58; }
    elseif ($speed <= 344){ $percentage1 = 59; }
    elseif ($speed <= 350){ $percentage1 = 60; }
    elseif ($speed <= 356){ $percentage1 = 61; }
    elseif ($speed <= 362){ $percentage1 = 62; }
    elseif ($speed <= 368){ $percentage1 = 63; }
    elseif ($speed <= 374){ $percentage1 = 64; }
    elseif ($speed <= 380){ $percentage1 = 65; }
    elseif ($speed <= 386){ $percentage1 = 66; }
    elseif ($speed <= 392){ $percentage1 = 67; }
    elseif ($speed <= 398){ $percentage1 = 68; }
    elseif ($speed <= 404){ $percentage1 = 69; }
    elseif ($speed <= 410){ $percentage1 = 70; }
    elseif ($speed <= 416){ $percentage1 = 71; }
    elseif ($speed <= 422){ $percentage1 = 72; }
    elseif ($speed <= 428){ $percentage1 = 73; }
    elseif ($speed <= 434){ $percentage1 = 74; }
    elseif ($speed <= 440){ $percentage1 = 75; }
    elseif ($speed <= 446){ $percentage1 = 76; }
    elseif ($speed <= 452){ $percentage1 = 77; }
    elseif ($speed <= 458){ $percentage1 = 78; }
    elseif ($speed <= 464){ $percentage1 = 79; }
    elseif ($speed <= 470){ $percentage1 = 80; }
    elseif ($speed <= 476){ $percentage1 = 81; }
    elseif ($speed <= 482){ $percentage1 = 82; }
    elseif ($speed <= 488){ $percentage1 = 83; }
    elseif ($speed <= 494){ $percentage1 = 84; }
    elseif ($speed <= 500){ $percentage1 = 85; }
    elseif ($speed <= 506){ $percentage1 = 86; }
    elseif ($speed <= 512){ $percentage1 = 87; }
    elseif ($speed <= 518){ $percentage1 = 88; }
    elseif ($speed <= 524){ $percentage1 = 89; }
    elseif ($speed <= 530){ $percentage1 = 90; }
    elseif ($speed <= 536){ $percentage1 = 91; }
    elseif ($speed <= 542){ $percentage1 = 92; }
    elseif ($speed <= 548){ $percentage1 = 93; }
    elseif ($speed <= 554){ $percentage1 = 94; }
    elseif ($speed <= 560){ $percentage1 = 95; }
    elseif ($speed <= 566){ $percentage1 = 96; }
    elseif ($speed <= 572){ $percentage1 = 97; }
    elseif ($speed <= 578){ $percentage1 = 98; }
    elseif ($speed <= 584){ $percentage1 = 99; }
    elseif ($speed >= 590){ $percentage1 = 100; }
    The Speed Goes Up By 6 and The Percentage Goes Up By 1 And At 100 Percentage The Speed Is Equal To or Greater Than!

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can Anyone Help?

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Only ten minutes between your posts. Have a bit of patience, we all have lives (well, most of us).
    PHP Code:
    $percentage1 ceil$speed );
    if ( 
    $percentage1 == )
        
    $percentage1 1;
    elseif ( 
    $percentage1 100 )
        
    $percentage1 100
    Last edited by kbluhm; 05-31-2007 at 11:03 PM.

  • #4
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    Even shorter, and even more unreadable
    PHP Code:
    $percentage1 $speed : ($speed 600 100 ceil($speed 6)); 

  • #5
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thankz guys they both work


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •