verhaba
Gebruiker
- Lid geworden
- 8 feb 2008
- Berichten
- 79
hallo
Ik heb een opdracht. de user geeft een getal in (bv 9) en een basis getal (bv 17). de waarden moeten als volgt opgeslagen worden. Op index 0 staat 17 (1 x 17), op index 1 staat 34 (2 x 17), op index 2 staat 51 ( 3 x 17) tot index 8. Daar staat 153 (9 x 17). Nadien vraagt de console een zoek getal. Staat die in de array dan moet de console dit ook weergeven. Indien niet ook natuurlijk. Maar meer text en uitleg hieronder.
Programmaverloop:
Count ? : 9
Base Value ? : 17
Search Value ? : 136
136 is the 8 multiple of 17
Search Value ? : 135
135 is not found in the first 9 multiples of 17
Search Value ? : 17
17 is the 1 multiple of 17
Search Value ? :
bij het uitvoeren mijn code (zie verder) krijg ik volgende boodschap.
"Make sure that the maximum index on a list is less than the list size."
De bedoeling is dat de reden van de boodschap snap. Niet zo zeer om jullie me de oplossing te geven, hoor. Bedoeling is dat er wat uit leer hé. Thx manne... en vrouwen ook natuurlijk... als die er zijn.
[VB]
Sub Main()
Console.WriteLine("count?")
Dim count As Integer = Console.ReadLine()
Console.WriteLine("Base Value?")
Dim baseValue As Integer = Console.ReadLine()
Dim upperbound As Integer = count - 1
Dim calc(upperbound) As Integer
' array initiëren en opvullen met de waarden.
Dim index As Integer
For index = 0 To upperbound
calc(index) = (baseValue * (index + 1))
'de array uitprinten
Console.Write(calc(index) & " ")
Next
Console.Write("Search value?")
Dim searchvalue As Integer = Console.ReadLine()
For index = 0 To upperbound
Dim found As Boolean = False
index = -1
Do Until found
index += 1
found = (calc(index) = searchvalue)
Loop
If found Then
Console.WriteLine(calc(index) & " is found in the first " & index & " multiples of " & count)
Else
Console.WriteLine(searchvalue & "is not found in the first " & upperbound & " multiples of " & count)
End If
Next
Console.ReadLine()
End Sub
[/VB]
Ik heb een opdracht. de user geeft een getal in (bv 9) en een basis getal (bv 17). de waarden moeten als volgt opgeslagen worden. Op index 0 staat 17 (1 x 17), op index 1 staat 34 (2 x 17), op index 2 staat 51 ( 3 x 17) tot index 8. Daar staat 153 (9 x 17). Nadien vraagt de console een zoek getal. Staat die in de array dan moet de console dit ook weergeven. Indien niet ook natuurlijk. Maar meer text en uitleg hieronder.
Programmaverloop:
Count ? : 9
Base Value ? : 17
Search Value ? : 136
136 is the 8 multiple of 17
Search Value ? : 135
135 is not found in the first 9 multiples of 17
Search Value ? : 17
17 is the 1 multiple of 17
Search Value ? :
bij het uitvoeren mijn code (zie verder) krijg ik volgende boodschap.
"Make sure that the maximum index on a list is less than the list size."
De bedoeling is dat de reden van de boodschap snap. Niet zo zeer om jullie me de oplossing te geven, hoor. Bedoeling is dat er wat uit leer hé. Thx manne... en vrouwen ook natuurlijk... als die er zijn.
[VB]
Sub Main()
Console.WriteLine("count?")
Dim count As Integer = Console.ReadLine()
Console.WriteLine("Base Value?")
Dim baseValue As Integer = Console.ReadLine()
Dim upperbound As Integer = count - 1
Dim calc(upperbound) As Integer
' array initiëren en opvullen met de waarden.
Dim index As Integer
For index = 0 To upperbound
calc(index) = (baseValue * (index + 1))
'de array uitprinten
Console.Write(calc(index) & " ")
Next
Console.Write("Search value?")
Dim searchvalue As Integer = Console.ReadLine()
For index = 0 To upperbound
Dim found As Boolean = False
index = -1
Do Until found
index += 1
found = (calc(index) = searchvalue)
Loop
If found Then
Console.WriteLine(calc(index) & " is found in the first " & index & " multiples of " & count)
Else
Console.WriteLine(searchvalue & "is not found in the first " & upperbound & " multiples of " & count)
End If
Next
Console.ReadLine()
End Sub
[/VB]