Code to Calculate Discount

Here to example of using loob with condition to calculate discount price.

Module Module1
Dim Action As Integer
Dim i As Integer
Dim price As Double
Dim discount As Double
Dim net As Double
Dim discount_percent As String

Sub Main()
Do

Console.WriteLine(“Main Menu”)
Console.WriteLine(“1. Show the discount info”)
Console.WriteLine(“2. Calculate the Discount”)
Console.WriteLine(“3. Show all Discount”)
Console.WriteLine(“4. Exit”)
Console.WriteLine(“Choose your action”)

Action = Console.ReadLine

If (Action = 1) Then
Console.WriteLine(“[0-1000]   5%”)
Console.WriteLine(“[1001-5000]   10%”)
Console.WriteLine(“[> 5000]   15%”)

ElseIf (Action = 2) Then
Console.WriteLine(“Please Enter the price”)
price = Console.ReadLine()
If (price < 0) Then
Console.WriteLine(“You can not the Negative Number”)

ElseIf (price >= 0) And (price <= 1000) Then
discount = 0.05
discount_percent = discount * 100
Console.WriteLine(“Discount Percentage is ={0}”, discount_percent)

ElseIf (price >= 1001) And (price <= 5000) Then
discount = 0.1
discount_percent = discount * 100
Console.WriteLine(“Discount Percentage is ={0}”, discount_percent)

Else
discount = 0.15
discount_percent = discount * 100
Console.WriteLine(“Discount Percentage is ={0}”, discount_percent)

End If

ElseIf (Action = 3) Then
Console.WriteLine(“The Price is={0}”, price)
Console.WriteLine(“The Percentage of Discount is={0}”, discount)
net = price * (1 – discount)

Console.WriteLine(“You have to pay={0}”, net)
ElseIf (Action = 4) Then
Console.WriteLine(“Exit”)
Else
Console.WriteLine(“You Ente the wrong number”)

End If
Console.ReadLine()
Console.Clear()

Loop While (Action = 1) Or (Action = 2) Or (Action = 3)

End Sub

End Module

Rounding Currency

Many of my friends at University has request me to post the homework code of Vb.net that I have done on my blog. and here the simple Vb.net Console Application that i’m learning at University. So I hope that younger or older brother that learning in IT can see the simple code and correct or implement it together.

-The Code are focus on how to use “IF Condition” and “Do Loop”.
Here is the Rounding Currency Code In VB.net Console Application

Module Module1

Sub Main()

Dim ROUND As Double
Dim amount As Double
Dim selected As Integer
Dim modulus As Double
Dim yesno As String

Do
Console.Clear()
Console.WriteLine(“Rounding Currency Table”)
Console.WriteLine(“1.RIEL”)
Console.WriteLine(“2.USD”)
Console.WriteLine(“3.EURO”)
Console.WriteLine(“4.POUND”)
Console.WriteLine(“Please Select the Currency”)
selected = Console.ReadLine

If (selected = 1) Then
Console.Clear()
Console.WriteLine(“1.RIEL”)
Console.WriteLine(“Input Amount:”)
amount = Console.ReadLine
modulus = amount Mod 100

If (modulus = 50) Then
ROUND = amount
ElseIf (modulus > 50) Then
ROUND = (amount – modulus) + 100
ElseIf (modulus < 50) Then
ROUND = amount – modulus
End If
Console.WriteLine(“Rounded Amount={0}Riel”, ROUND)
ElseIf (selected = 2) Then
Console.Clear()
Console.WriteLine(“2.USD”)
Console.WriteLine(“Input Amount”)
amount = Console.ReadLine
Console.WriteLine(“Rounded Amount={0} USD”, amount)
ElseIf (selected = 3) Then
Console.Clear()
Console.WriteLine(“3.EURO”)
Console.WriteLine(“Input Amount”)
amount = Console.ReadLine
Console.WriteLine(“Rounded Amount={0} EURO”, amount)
ElseIf (selected = 4) Then
Console.Clear()
Console.WriteLine(“4.POUND”)
Console.WriteLine(“Input Amount”)
amount = Console.ReadLine
Console.WriteLine(“Rounded Amount={0} POUND”, amount)
Else
Console.WriteLine(“Wrong Selection”)
End If
Console.WriteLine(“Do you want to continue (Y|N)? “)
yesno = Console.ReadLine

Loop Until (yesno = “n”)

End Sub

End Module

If you have any problem of running the program or need to ask inside code, please fill free to ask me. I might be available from my best tried.