Solved

Pseudocode

Posted on 2004-10-09
9
333 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now