473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to simplify this long if else statement to for loop or an array

24
Hi,

I need a simple code for the following code, may be a (for loop) or (an array) or (a simple if else) can accomplish this task, but I don't know how to do that.

$tax1 is related to $discount1.
$tax2 is related to $discount2.
$tax3 is related to $discount3.

Please help me. Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. if ($discount1 == 100 && $discount2 == 100 && $discount3 == 100) 
  2. $total_price = $price - $tax1 - $tax2 - $tax3
  3.  
  4. elseif ($discount2 == 100 && $discount3 == 100)
  5. $total_price = $price - $tax2 - $tax3
  6.  
  7. elseif ($discount1 == 100 && $discount3 == 100)
  8. $total_price = $price - $tax1 - $tax3
  9.  
  10. elseif ($discount1 == 100 && $discount2 == 100)
  11. $total_price = $price - $tax1 - $tax2
  12.  
  13. elseif ($discount1 == 100)
  14. $total_price = $price - $tax1
  15.  
  16. elseif ($discount2 == 100)
  17. $total_price = $price - $tax2
  18.  
  19. elseif ($discount3 == 100)
  20. $total_price = $price - $tax3
  21.  
  22. else
  23. $total_price = $price
  24.  
Feb 6 '11 #1
1 1670
Rabbit
12,516 Expert Mod 8TB
You already asked this question here http://bytes.com/topic/asp-classic/a...else-statement.
Feb 6 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
4
by: Daryl Davis | last post by:
I am having trouble with ReDim (see code below) SaleTable2's structure includes an array for SaleDetailTable2 Dim newsale As New hallsales.SaleTable2 Dim detail As New hallsales.SaleDetailTable2...
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
1
by: akcharter | last post by:
I am incorporating a pre-existing classifieds program into my website. I would like to charge a nominal fee for ads listing items over $100. I think an if ... else statement would work best in this...
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
2
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.