Write a program in BASIC that compute total charges for phones sold and displays this information to the screen.
The program must prompt the user for the price of a phone. Compute the sales tax for this value, and then display the phone price, the dollar amount of the sales tax, and the total charge for this purchase. Sales tax is calculated as 7% of the price of the phone. Total charge is the price plus the sales tax amount.
After all the data has been entered, display a grand total of number of phones sold, and a grand total of all total charges.
This program must use at least two subroutines.
Module Module1
Sub Main()
Dim pricePhone As Double = 0
Dim grandTotalNumberPhonesSold As Integer = 0
Dim totalAllTotalCharges As Double = 0
While pricePhone >= 0
'prompt the user for the price of a phone.
Console.Write("Enter the price of a phone (-1 to close): ")
pricePhone = Double.Parse(Console.ReadLine())
If (pricePhone >= 0) Then
'Compute the sales tax for this value
Dim salesTax As Double = calculateSalesTax(pricePhone)
Dim totalCharge As Double = calculateTotalCharge(pricePhone, salesTax)
'Display the phone price, the dollar amount of the sales tax, and the total charge for this purchase.
Console.WriteLine("The phone price: " + pricePhone.ToString("C"))
Console.WriteLine("The sales tax: " + salesTax.ToString("C"))
Console.WriteLine("The total charge: " + totalCharge.ToString("C"))
Console.WriteLine()
grandTotalNumberPhonesSold += 1
totalAllTotalCharges += totalCharge
End If
End While
'After all the data has been entered, display a grand total of number of phones sold, and a grand total of all total charges.
Console.WriteLine()
Console.WriteLine("The grand total of number of phones sold: " + grandTotalNumberPhonesSold.ToString())
Console.WriteLine("The grand total of all total charges: " + totalAllTotalCharges.ToString("C"))
Console.ReadLine()
End Sub
''' <summary>
''' Calculates sales tax is calculated as 7% of the price of the phone.
''' </summary>
''' <param name="pricePhone"></param>
''' <returns></returns>
''' <remarks></remarks>
Function calculateSalesTax(ByVal pricePhone As Double) As Double
Return pricePhone * 0.07D
End Function
''' <summary>
''' Total charge is the price plus the sales tax amount.
''' </summary>
''' <param name="pricePhone"></param>
''' <param name="salesTax"></param>
''' <returns></returns>
''' <remarks></remarks>
Function calculateTotalCharge(ByVal pricePhone As Double, ByVal salesTax As Double) As Double
Return pricePhone + salesTax
End Function
End Module
Comments
Leave a comment