Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Asp Calculation

Hi,
I'd like to know how to do a simple calculation in ASP. I have a normal form fro an airline ticketing system below:




Your name:

Your Age:

Luggage Weight:






And I'd like to know how display the following on the web browser when 'submit' is hit:

Current Date, Passenger Name, Passenger Age (10% discount on the basic price for children under 12), Discount, Luggage in Kg (passengers are charged extra 3 for every 1kg over 20kg), Luggage Surcharge, and Ticket Price (normally 90 + Vat at 21%)

I attempted it but it's not working for some reason...
It looks messy. I'd appreciate it if you could help me with it. Thanks in advance. (I love the website!!)


<%

dim fname
dim age
dim weight
dim CalculateDiscount
dim CalculateSurcharge
dim TicketPrice
dim Vat
dim TotalPrice
TicketPrice = 90
vat = 0.21
varCalculateDiscount=0
varCalculateSurcharge=0




fname=Request.Form("fname")
If fname<>"" Then
Response.Write("Hello " &fname & "!
")
Response.Write("How are you today?")
End If

age=Request.Form("age")
If age<>"" Then
Response.Write("You are " &age & "years old.")
End If




'Calculations based on passenger input
'----------------------------------------

If varage < 12 Then
varCalculateDiscount = TicketPrice * 0.1

End If


If varweight > 20 Then
varCalculateSurcharge = (varLuggageWeight - 20) * 3

End if

varTicketPrice = (TicketPrice - varCalculateDiscount)
varVat = varTicketPrice * 0.21
TotalPrice = varTicketPrice + varVat + varCalculateSurcharge

Response.Write "Passenger Name:" & varFullName & "
"
Response.Write "Passenger Age:" & varAge & "
"
Response.Write "Discount: " & varCalculateDiscount & "
"
Response.Write "Luggage Weight: " & varWeight & "Kg" & "
"
Response.Write "Luggage surcharge: " & varCalculateSurcharge & "
"
Response.Write "Ticket Price: " & TotalPrice

%>


Comments

  • FlakesFlakes Posts: 642Member
    : Hi,
    : I'd like to know how to do a simple calculation in ASP. I have a normal form fro an airline ticketing system below:
    :
    :
    :
    :
    : Your name:
    : Your Age:
    : Luggage Weight:
    :
    :
    :
    :
    :
    : And I'd like to know how display the following on the web browser when 'submit' is hit:
    :
    : Current Date, Passenger Name, Passenger Age (10% discount on the basic price for children under 12), Discount, Luggage in Kg (passengers are charged extra 3 for every 1kg over 20kg), Luggage Surcharge, and Ticket Price (normally 90 + Vat at 21%)
    :
    : I attempted it but it's not working for some reason...
    : It looks messy. I'd appreciate it if you could help me with it. Thanks in advance. (I love the website!!)
    :
    :
    : <%
    :
    : dim fname
    : dim age
    : dim weight
    : dim CalculateDiscount
    : dim CalculateSurcharge
    : dim TicketPrice
    : dim Vat
    : dim TotalPrice
    : TicketPrice = 90
    : vat = 0.21
    : varCalculateDiscount=0
    : varCalculateSurcharge=0
    :
    :
    :
    :
    : fname=Request.Form("fname")
    : If fname<>"" Then
    : Response.Write("Hello " &fname & "!
    ")
    : Response.Write("How are you today?")
    : End If
    :
    : age=Request.Form("age")
    : If age<>"" Then
    : Response.Write("You are " &age & "years old.")
    : End If
    :
    :
    :
    :
    : 'Calculations based on passenger input
    : '----------------------------------------
    :
    : If varage < 12 Then
    : varCalculateDiscount = TicketPrice * 0.1
    :
    : End If
    :
    :
    : If varweight > 20 Then
    : varCalculateSurcharge = (varLuggageWeight - 20) * 3
    :
    : End if
    :
    : varTicketPrice = (TicketPrice - varCalculateDiscount)
    : varVat = varTicketPrice * 0.21
    : TotalPrice = varTicketPrice + varVat + varCalculateSurcharge
    :
    : Response.Write "Passenger Name:" & varFullName & ""
    : Response.Write "Passenger Age:" & varAge & ""
    : Response.Write "Discount: " & varCalculateDiscount & ""
    : Response.Write "Luggage Weight: " & varWeight & "Kg" & ""
    : Response.Write "Luggage surcharge: " & varCalculateSurcharge & ""
    : Response.Write "Ticket Price: " & TotalPrice
    :
    : %>
    :
    :
    :

    Looks OK to me except that you have mixed up some variables ,like you have declared age and is using varage ,declared weight and is using varweight etc...

    Change those and see what happens.

Sign In or Register to comment.