Solved

Pseudocode

Posted on 2004-10-09
9
337 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

929 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

20 Experts available now in Live!

Get 1:1 Help Now