Solved

# Pseudocode

Posted on 2004-10-09
333 Views
I was trying to write a pseudocode abd i was wandering if it was incorrect to do the following

If vacationDays <= 2 then
stay home
Else
if vacationDays >2 and<4 then
Go Nashville
Endif

0
Question by:jahsexy18
• 5
• 3

LVL 15

Expert Comment

ID: 12266988
Hi

yeah you can add the additional if but it would be as an ElseIf

Also you would need to specify vacationDays in the second clause of the ElseIf like so

If vacationDays <= 2 then
stay home
Elseif vacationDays >2 and vacationDays<4 then
Go Nashville
Endif

You could also have a final Else statement after the ElseIf which would catch any vacationDays that didnt match any of the other expressions

HTH but if you need any more explanation just let me know

Cheers

Scott
0

LVL 10

Expert Comment

ID: 12267011
is there any action for vacation >= 4?
if not...u can simply write it as..

If vacationDays <= 2 then
stay home
Else
Go Nashville
Endif

this is not the most correct way, but it will do the same thing as per the first code
:-)
0

LVL 15

Expert Comment

ID: 12267060
Forgot to mention you could also have multiple ElseIfs like this

If vacationDays <= 2 then
stay home
Elseif vacationDays >2 and vacationDays<4 then
Go Nashville
Elseif vacationDays >3 and vacationDays<5 then
Go Location2
Elseif vacationDays >4 and vacationDays<6 then
Go Location3
Endif

Also vacationDays >2 and vacationDays<4 is the same as saying vacationDays = 3

Cheers

Scott
0

Author Comment

ID: 12267084
Would it be correct if written like this

If vacationDays <= 2 then
stay home
Elseif vacationDays >2 and vacationDays<4 then
Go Nashville
Endif

Else
If vacationDays >=4 then
Check budget
Endif

If budget >=\$1200 then
Go Aruba
Else if budget >\$800 then
Go Miami
Else
Go Orlando

End if
0

LVL 15

Expert Comment

ID: 12267116
Almost it would have to be like this though

If vacationDays <= 2 then
stay home
Elseif vacationDays = 3 then
Go Nashville
Else
Check budget
Endif

If budget >=\$1200 then
Go Aruba
Else if budget >\$800 then
Go Miami
Else
Go Orlando
End if

Note: vacationDays = 3 is better(more efficient) than  vacationDays >2 and vacationDays<4

Also

Else
Check budget

this is better again because in your code it is the same as

ElseIf vacationDays >=4 then
Check budget

HTH

Scott
0

Author Comment

ID: 12267198
Thanks Scott
I am not sure if I am writing discount in the correct way and also the last if ststement with premium customer

If totalAmount <\$20 then
Discount=0
Elseif totalAmount >\$20 and <\$50 then
Discount=5%
Elseif totalAmount >\$50 and<\$100 then
Discount=10%
Endif

Else
If totalAmount >=\$100 and premiumCustomer then
Discount=20%
Else
Discount=15%
0

LVL 15

Accepted Solution

Colosseo earned 500 total points
ID: 12267295
Hi

A quiick overview of the way If statements are structured is like this

If [expression] Then

ElseIf [expression] Then

Else

End If

Notes:

In the above ElseIf and Else are optional.

You can have multiple ElseIf statements but only one Else

An If needs an End If... unless written on one line like this...

If [expression] Then [action] Else [action2] (the else here is optional)

Every Else or ElseIf should be inside an If End If pairing

The way I would write your if statement above is this:

assuming totalAmount must have a value then totalAmount >=\$100 is not required because by time we get too

totalAmount must be greater than or equal to 100 so there is no need to check

If totalAmount <\$20 then
Discount=0
Elseif totalAmount >=\$20 and totalAmount <\$50 then
Discount=5%
Elseif totalAmount >=\$50 andtotalAmount <\$100 then
Discount=10%
Discount=20%
Else
Discount=15%
End If

HTH

Scott
0

Author Comment

ID: 12267333
thanks scott I rally learned alot from you and I clearly understand now
0

LVL 15

Expert Comment

ID: 12267382

Cheers

Scott
0

## Featured Post

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …