'da bir hesaplama içeren bir altprogramda bir diziden sayı alınıyor Bu yüzden konsol uygulamasının kullanıcıya ad, saat ve ödeme yapmasını istemek zorundayım. Bu cevaplar uygun dizilerde saklanacaktır. Bir alt yordam içinde bulunan bir hesaplamada saat payrate dizilerden bilgileri kullanmak gerekir. Ben veya online benim ders kitabı aracılığıyla ipucu çeşit bulmaya çalıştılar ama bu durumda bana yardımcı oluyor şey ...VB
Ben şu satırlarda alıyorum hatayı anlamıyorum bulmak için görünmüyor olabilir.
total = overtimePay(hours(i), rate(i))
total = regularPay(hours(i), rate(i))
i almak hatadır:
"türü 'Çift' Değerprogramıma bir 'double 1 boyutlu dizide' haline dönüştürülemez
tamamen çalışır ben sadece alt rutinlerin yerine buraya hesaplama denklemleri koyduğunuzda İşte
benim kod bütünüdür.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
dizi saatinden öğenin çifte değeridir. Her birinde okumayı istediğimi nasıl anlarım? her iki dizinin sayısı? Yaptığın öneri denedik ama hala aynı hata sonucu ediyorum ... – cryosneasel
Aslında sadece sorunu çözdüm. Alt programları bir işleve değiştirdim ve iyi çalışıyor. Öğretmenimiz bize bir altprogram olduğunu söyleyen altprogramların kodunu verdi. Oh iyi. Şimdi işe koyuldum. Yardımın için teşekkürler! – cryosneasel