computer programming (Program Bug and Problems)

by Asy, Sunday, March 17, 2013, 15:54 (1587 days ago)

Hi.May you help me with question given.

Determine price after discount. Based on data price entered by user. The discount structure is :

price below and equal 100 : discount = 0%

price between 100 and 200: discount = 10%

price above and equal 200: discount = 20%

this is my solution:>
print "what is the price (RM)?"
input P
If P<=100 Then
PE=(0/100)*P
Endif
If 100<P<200 Then
PE=(10/100)*P
Endif
If P>=200 Then
PE=(20/100)*P
Endif
P=P-PE
print "The price is " +P

I don't know where is my fault.I calculated the price for P<=100 (
price below and equal 100 : discount = 0%) but I got the price is for
price between 100 and 200: discount = 10% .

computer programming

by lrcvs, Sunday, March 17, 2013, 17:39 (1587 days ago) @ Asy

CLS
J = 0
K = 0
T = 0
print "what is the price (RM)?"
input P
If P <= 100 Then T = P
IF P > 100 THEN J = 1
IF P <= 200 THEN K = 1
IF J = 1 AND K = 1 THEN T = P - (10*P) / 100
If P > 200 Then T = P - (P * 20) / 100
print "The price is = " + T
END

computer programming

by Asy, Sunday, March 24, 2013, 14:55 (1580 days ago) @ lrcvs

thanks :)

computer programming

by Andrew360 @, Monday, March 25, 2013, 21:08 (1578 days ago) @ Asy

Your fault is this line:

If 100<P<200 Then

Here's what happens:

-The program will decide whether or not 100 is less than the price (P).
-This will return a binary flag, either true (1) or false (0).
-The program then decides whether or not the flag (1 or 0) is less than 200.
-This is always true, so PE is set to 1/10th of P regardless of what P equals.
-If P is greater than 200, PE is set to 1/5th of P.

Replace the line with:

If 100<P and P<200 Then


I hope this helps you in the future!

RSS Feed of thread
powered by my little forum