我想回答一個問題,我必須在visual basic中使用案例。如何讓案件工作
的問題是:
編寫一個程序,要求用戶進行的小時數在本週和他們的工資每小時工資標準。該計劃是計算草薪水。如果工作的小時數大於40,那麼額外的小時數將以1.5倍的費率支付。如果工作的小時數不在0到60的範圍內,程序應顯示一條錯誤消息。
這是我寫的代碼,關於出錯的任何想法將不勝感激。在第一
Console.WriteLine("This will calculate the gross profit from the hours you work and the hourly pay")
Console.WriteLine("Your work hours can not be under 0 or above 60,
if you work above 40 hours the extra hours will be 1.5 times the original")
Console.Write("Please enter the hours you work a week: ")
Dim hours As Integer = Console.ReadLine()
Console.Write("Please enter the hourly pay you get: ")
Dim hourlyPay As Decimal = Console.ReadLine()
Dim message As String = "Your gross pay per week is: £"
Dim weeklyPay As Decimal
Select Case hours
Case 0 < hours < 40
weeklyPay = hours * hourlyPay
Case hours > 40 And hours < 60
weeklypay = ((40 * hourlyPay) + ((hours - 40) * (hourlyPay * 1.5)))
Case hours < 0 Or hours > 60
message = "Sorry the hours you entered are above the range try again"
End Select
Console.WriteLine(message & weeklyPay.ToString("N2"))
Console.ReadLine()
我們怎麼知道哪裏出了問題? –
[Select Case Docs](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement)和[Select Case Statement](https:// msdn.microsoft.com/VBA/Language-Reference-VBA/articles/select-case-statement)也請閱讀[問]並參加[旅遊]。同時打開Option Strict – Plutonix
如果我爲任何輸入內容輸入「ABC」,該怎麼辦?記住整數/小數不是字符串,你不應該在編譯器上中繼來讓你更容易。選項嚴格在 – Steve