したがって、コンソールアプリケーションにユーザーに名前、時間、および支払いを依頼する必要があります。これらの回答は、適切な配列に格納されます。私は時間からの情報を使用し、サブルーチンに含まれる計算で配列を支払う必要があります。私は教科書やオンラインで何らかのヒントを見つけようとしましたが、この状況で私を助けるものは見つけられませんでした...VBからの計算を含むサブルーチンに配列から数値を取得する
私はこのエラーを理解していません。
total = overtimePay(hours(i), rate(i))
total = regularPay(hours(i), rate(i))
私が取得エラーです:型 『ダブル』の値が
『ダブルの1次元 配列』に変換することができません
」私のプログラムは完全に動作しますサブルーチンの代わりにここに計算式を入れたとき
ここに私のコードの全体があります。
Module FinalAssignment1 Sub Main() 'Author: Russell Peryy 'Date: 4/2/16 'Purpose: User enters info and program outputs the entered pay and calculated info 'Declare constants Const author As String = "Russell Perry =================== Final Assignment 1" Const lines As String = "====================================================" 'Declare Arrays Dim names(0 To 10) As String Dim hours(0 To 10) As Double Dim rate(0 To 10) As Double 'Dim total(0 To 10) As Double 'Declare variabels Dim i As Integer = 0 Dim total As Double = 0 'Display constants Console.WriteLine(author) Console.WriteLine(lines) space(1) 'Get user information to fill name, hours, and rate array For i = 0 To 9 Step 1 Console.Write("Enter employee's last name >> ") names(i) = Console.ReadLine() Console.Write("Enter employee's hours worked >> ") hours(i) = Console.ReadLine() Console.Write("Enter the employee's pay rate >> ") rate(i) = Console.ReadLine() 'i = i + 1 space(1) Next space(1) Console.WriteLine(lines) 'Print info to screen For i = 0 To 9 Step 1 If hours(i) >= 40 Then total = overtimePay(hours(i), rate(i)) 'total = (40 * rate(i)) + ((hours(i) - 40) * rate(i) * 1.5) Else total = regularPay(hours(i), rate(i)) 'total = hours(i) * rate(i) End If Console.WriteLine(names(i) & " worked " & hours(i) & " at a rate of " & String.Format("{0:C}", rate(i)) & " an hour for a total pay of " & String.Format("{0:C}", total)) Next i 'Pause the screen space(1) Console.WriteLine(lines) space(1) Console.Write("Press any key to exit >> ") Console.ReadKey() End Sub 'subroutine for adding spaces Sub space(ByVal x As Integer) For counter = 0 To x Console.WriteLine() Next End Sub 'Subroutine for regular pay Sub regularPay(ByVal array1() As Double, ByVal array2() As Double, ByVal i As Integer) Dim t As Double = array1(i) * array2(i) End Sub 'subroutine for overtime Sub overtimePay(ByVal array1() As Double, ByVal array2() As Double, ByVal i As Integer) Dim total As Double = ((40 * array2(i)) + ((array1(i) - 40) * array2(i) * 1.5)) End Sub End Module
したがって、それぞれを読みたい両方の配列の数?私はあなたが作った提案を試みましたが、私はまだ同じエラーが発生しています... – cryosneasel
実際に私は問題を把握しました。私は関数にサブルーチンを変更し、正常に動作します。私たちの先生は、それがサブルーチンだと言っているサブルーチンのコードを教えてくれました。しかたがない。私は今働くようになった。ご協力ありがとうございました! – cryosneasel