当一个人提供与物品价格相同数量的现金时,试图打印 0 值
Trying to print a 0 value when a person gives the same amount of cash as what the price of the item is
基本上当我不通过我的 CashedOwed 变量传递 ##.## 时,它会显示 $0.000。如果我这样做,那么它将打印为金钱符号,但后面没有数字。
我不确定如何修复它,或者我还能做什么。老实说,我已经为此工作了几个小时,并且已经使用我正在创建的程序完成了许多 bugs/issues/concepts(这是我在大学时的编程 class。)
'Service number variable
Dim snum As String
'Haircut description variables. Variable names are acronymns of the hair styles
Dim str_mdc As String = "Men's dry cut"
Dim str_mwc As String = "Men's wash and cut"
Dim str_lwcb As String = "Ladies wash, cut & blow dry"
Dim str_lccs As String = "Ladies color, cut & style"
Dim str_lcfcs As String = "Ladies color, foils, cut & style"
Dim hairstyle As String
'If person is 65 or older variable
Dim seniordisc As String
'How much cash is given towards the haircut variable
Dim cashpaid As Decimal
Dim cash As Decimal
'Prices variables, which then store in the price variable when it's selected in the case
Dim price1 As Decimal = 18.75
Dim price2 As Decimal = 29.5
Dim price3 As Decimal = 38.75
Dim price4 As Decimal = 79.8
Dim price5 As Decimal = 95.5
Dim price As Decimal
'calculation variables
Dim haircutprice As Decimal
Dim tax As Decimal = 1.15
Dim TotalWithTax As Decimal
Dim discount As Decimal = 1.15
Dim CashOwed As Double
Sub Main()
'initializes the console and variables.
Console.Clear()
'Prints out the menu for Sally's Shear Delight
Console.WriteLine("----------------------------------------------------------")
Console.WriteLine("Sally’s Shear Delight")
Console.WriteLine("----------------------------------------------------------")
Console.WriteLine("Service Number | Description | Price")
Console.WriteLine("----------------------------------------------------------")
Console.WriteLine($"1 | {str_mdc} | ${price1}")
Console.WriteLine($"2 | {str_mwc} | ${price2}")
Console.WriteLine($"3 | {str_lwcb} | ${price3}")
Console.WriteLine($"4 | {str_lccs} | ${price4}")
Console.WriteLine($"5 | {str_lcfcs} | ${price5}")
'Writes a line in the console, prompting user to input service number
Console.WriteLine($"{vbCrLf}Enter the number of which service is required.")
snum = Console.ReadLine 'stores the value inside of the variable
Select Case snum
Case "1"
'haircut style
str_mdc = "Men's dry cut"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
Case "2"
'haircut style
str_mwc = "Men's wash and cut"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
Case "3"
'haircut style
str_lwcb = "Ladies wash, cut & blow dry"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
'prompts user to enter the amount of cash given
Console.WriteLine("Enter amount of cash given")
cash = Console.ReadLine
Case "4"
'haircut style
str_lccs = "Ladies color, cut & style"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
'prompts user to enter the amount of cash given
Case "5"
'haircut style
str_lcfcs = "Ladies color, foils, cut & style"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
Case Else
Main()
End Select
Select Case snum
Case "1"
price = price1
Case "2"
price = price2
Case "3"
price = price3
Case "4"
price = price4
Case "5"
price = price5
End Select
Select Case snum
Case "1"
hairstyle = str_mdc
Case "2"
hairstyle = str_mwc
Case "3"
hairstyle = str_lwcb
Case "4"
hairstyle = str_lccs
Case "5"
hairstyle = str_lcfcs
End Select
Select Case seniordisc
Case "y"
haircutprice = price
discount = (price / 10) * 2
TotalWithTax = (haircutprice - discount) * tax
Console.WriteLine($"{vbCrLf}The total is: ${TotalWithTax:##.##}")
Console.WriteLine($"{vbCrLf}Enter amount of cash given")
cash = Console.ReadLine
CashOwed = cash - TotalWithTax
Console.WriteLine($"{vbCrLf}----------------------------------------------------------")
Console.WriteLine("Sally’s Shear Delight")
Console.WriteLine($"{vbCrLf}RECEIPT")
Console.WriteLine($"----------------------------------------------------------")
Console.WriteLine($"Haircut Style: {hairstyle}")
Console.WriteLine($"Price of haircut: ${price}")
Console.WriteLine($"Senior's discount: {discount:##.##}")
Console.WriteLine($"Total amount after discount: {TotalWithTax:##.##}")
Console.WriteLine($"Amount paid: ${cash:##.##}")
Console.WriteLine($"Cash owed: ${CashOwed}")
Case "n"
haircutprice = price
TotalWithTax = (haircutprice * tax)
Console.WriteLine($"{vbCrLf}The total is: ${TotalWithTax:##.##}")
Console.WriteLine($"{vbCrLf}Enter amount of cash given")
cash = Console.ReadLine
CashOwed = cash - TotalWithTax
Console.WriteLine($"{vbCrLf}----------------------------------------------------------")
Console.WriteLine("Sally’s Shear Delight")
Console.WriteLine($"{vbCrLf}RECEIPT")
Console.WriteLine($"----------------------------------------------------------")
Console.WriteLine($"Haircut Style: {hairstyle}")
Console.WriteLine($"Price of haircut: ${price}")
Console.WriteLine($"Total amount: {TotalWithTax:##.##}")
Console.WriteLine($"Amount paid: ${cash:##.##}")
Console.WriteLine($"Cash owed: ${CashOwed}")
Case Else
Main()
End Select
Console.ReadKey()
End Sub
对于要格式化为货币的每个值,您可以删除前面的美元符号并执行如下操作。
Console.WriteLine($"Cash Owed {CashOwed:C2}")
C2 将格式化为带 2 个小数位的货币
基本上当我不通过我的 CashedOwed 变量传递 ##.## 时,它会显示 $0.000。如果我这样做,那么它将打印为金钱符号,但后面没有数字。
我不确定如何修复它,或者我还能做什么。老实说,我已经为此工作了几个小时,并且已经使用我正在创建的程序完成了许多 bugs/issues/concepts(这是我在大学时的编程 class。)
'Service number variable
Dim snum As String
'Haircut description variables. Variable names are acronymns of the hair styles
Dim str_mdc As String = "Men's dry cut"
Dim str_mwc As String = "Men's wash and cut"
Dim str_lwcb As String = "Ladies wash, cut & blow dry"
Dim str_lccs As String = "Ladies color, cut & style"
Dim str_lcfcs As String = "Ladies color, foils, cut & style"
Dim hairstyle As String
'If person is 65 or older variable
Dim seniordisc As String
'How much cash is given towards the haircut variable
Dim cashpaid As Decimal
Dim cash As Decimal
'Prices variables, which then store in the price variable when it's selected in the case
Dim price1 As Decimal = 18.75
Dim price2 As Decimal = 29.5
Dim price3 As Decimal = 38.75
Dim price4 As Decimal = 79.8
Dim price5 As Decimal = 95.5
Dim price As Decimal
'calculation variables
Dim haircutprice As Decimal
Dim tax As Decimal = 1.15
Dim TotalWithTax As Decimal
Dim discount As Decimal = 1.15
Dim CashOwed As Double
Sub Main()
'initializes the console and variables.
Console.Clear()
'Prints out the menu for Sally's Shear Delight
Console.WriteLine("----------------------------------------------------------")
Console.WriteLine("Sally’s Shear Delight")
Console.WriteLine("----------------------------------------------------------")
Console.WriteLine("Service Number | Description | Price")
Console.WriteLine("----------------------------------------------------------")
Console.WriteLine($"1 | {str_mdc} | ${price1}")
Console.WriteLine($"2 | {str_mwc} | ${price2}")
Console.WriteLine($"3 | {str_lwcb} | ${price3}")
Console.WriteLine($"4 | {str_lccs} | ${price4}")
Console.WriteLine($"5 | {str_lcfcs} | ${price5}")
'Writes a line in the console, prompting user to input service number
Console.WriteLine($"{vbCrLf}Enter the number of which service is required.")
snum = Console.ReadLine 'stores the value inside of the variable
Select Case snum
Case "1"
'haircut style
str_mdc = "Men's dry cut"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
Case "2"
'haircut style
str_mwc = "Men's wash and cut"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
Case "3"
'haircut style
str_lwcb = "Ladies wash, cut & blow dry"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
'prompts user to enter the amount of cash given
Console.WriteLine("Enter amount of cash given")
cash = Console.ReadLine
Case "4"
'haircut style
str_lccs = "Ladies color, cut & style"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
'prompts user to enter the amount of cash given
Case "5"
'haircut style
str_lcfcs = "Ladies color, foils, cut & style"
'prompts the user with a y/n option. returns to main if they hit something else
Console.WriteLine("Is the customer 65 or older? y/n")
seniordisc = Console.ReadLine
Case Else
Main()
End Select
Select Case snum
Case "1"
price = price1
Case "2"
price = price2
Case "3"
price = price3
Case "4"
price = price4
Case "5"
price = price5
End Select
Select Case snum
Case "1"
hairstyle = str_mdc
Case "2"
hairstyle = str_mwc
Case "3"
hairstyle = str_lwcb
Case "4"
hairstyle = str_lccs
Case "5"
hairstyle = str_lcfcs
End Select
Select Case seniordisc
Case "y"
haircutprice = price
discount = (price / 10) * 2
TotalWithTax = (haircutprice - discount) * tax
Console.WriteLine($"{vbCrLf}The total is: ${TotalWithTax:##.##}")
Console.WriteLine($"{vbCrLf}Enter amount of cash given")
cash = Console.ReadLine
CashOwed = cash - TotalWithTax
Console.WriteLine($"{vbCrLf}----------------------------------------------------------")
Console.WriteLine("Sally’s Shear Delight")
Console.WriteLine($"{vbCrLf}RECEIPT")
Console.WriteLine($"----------------------------------------------------------")
Console.WriteLine($"Haircut Style: {hairstyle}")
Console.WriteLine($"Price of haircut: ${price}")
Console.WriteLine($"Senior's discount: {discount:##.##}")
Console.WriteLine($"Total amount after discount: {TotalWithTax:##.##}")
Console.WriteLine($"Amount paid: ${cash:##.##}")
Console.WriteLine($"Cash owed: ${CashOwed}")
Case "n"
haircutprice = price
TotalWithTax = (haircutprice * tax)
Console.WriteLine($"{vbCrLf}The total is: ${TotalWithTax:##.##}")
Console.WriteLine($"{vbCrLf}Enter amount of cash given")
cash = Console.ReadLine
CashOwed = cash - TotalWithTax
Console.WriteLine($"{vbCrLf}----------------------------------------------------------")
Console.WriteLine("Sally’s Shear Delight")
Console.WriteLine($"{vbCrLf}RECEIPT")
Console.WriteLine($"----------------------------------------------------------")
Console.WriteLine($"Haircut Style: {hairstyle}")
Console.WriteLine($"Price of haircut: ${price}")
Console.WriteLine($"Total amount: {TotalWithTax:##.##}")
Console.WriteLine($"Amount paid: ${cash:##.##}")
Console.WriteLine($"Cash owed: ${CashOwed}")
Case Else
Main()
End Select
Console.ReadKey()
End Sub
对于要格式化为货币的每个值,您可以删除前面的美元符号并执行如下操作。
Console.WriteLine($"Cash Owed {CashOwed:C2}")
C2 将格式化为带 2 个小数位的货币