Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Pseudocode

Posted on 2004-10-09
9
Medium Priority
?
352 Views
Last Modified: 2010-04-17
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

      
can I add that additional If
0
Comment
Question by:jahsexy18
  • 5
  • 3
9 Comments
 
LVL 15

Expert Comment

by:Colosseo
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

by:kiranghag
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

by:Colosseo
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:jahsexy18
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

by:Colosseo
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

by:jahsexy18
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

by:
Colosseo earned 2000 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

ElseIf premiumCustomer then

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%
     ElseIf premiumCustomer then
          Discount=20%
     Else    
          Discount=15%
     End If

HTH

Scott
0
 

Author Comment

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

Expert Comment

by:Colosseo
ID: 12267382
Glad to help and thanks for the grade

Cheers

Scott
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question