Попытка напечатать значение 0, когда человек дает ту же сумму денег, что и цена товара - PullRequest
0 голосов
/ 26 октября 2019

Обычно, когда я не пропускаю ##. ## через переменную CashedOwed, он будет отображать $ 0,000. Если я это сделаю, то он будет распечатан как денежный знак, но без цифр.

Я не уверен, как это исправить, или что еще я действительно могу сделать. Я честно работал над этим в течение нескольких часов и работал над многими ошибками / проблемами / концепциями с программой, которую я создаю (это для моего класса программирования в колледже.)

'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

1 Ответ

0 голосов
/ 27 октября 2019

Для каждого значения, которое вы хотите отформатировать как валюту, вы можете убрать знак доллара спереди и сделать что-то вроде следующего.

Console.WriteLine($"Cash Owed {CashOwed:C2}")

C2 будет форматироваться как валюта с двумя десятичными знаками

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...