Having trouble passing array to function
By : Lucas Carmona Ampuer
Date : March 29 2020, 07:55 AM
it fixes the issue This looks like a school assignment and I applaud you for not asking for the answer. There are several ways to do it, but you are already fairly close in the approach that you are using. When you pass an array reference, you do not want to include the length of the array. For example, the parameter int score[100] should be int score[]. The exception, especially in your scenario, is with multidimensional arrays. In this case, you want to use char playerName[][20]. Your function declaration also needs to change to match. Don't forget InputData returns an int. Your declarations and function call are correct; you just need to adjust your function signature.
|
Array and function trouble
By : Ronald
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You are setting the value of the string only at the start of your main routine. You need to set it after the ThreeResults are set. Strings are immutable objects, so your code would not work. code :
Module Module1
Sub Main()
'Declare Variables
Dim UserAnswer As String = "nothing"
Dim UserTokens As String
Dim ThreeResults(2) As String
Dim Result1 As String
Dim Result2 As String
Dim Result3 As String
'Ask user for number of tokens
Console.WriteLine("Enter the number of tokens that you want to gamble with (minimum of 1 token)")
UserTokens = (Console.ReadLine())
UserTokens = ValidateTokens(UserTokens)
Do Until UserAnswer = "no"
ThreeResults = GenerateNumbers()
Result1 = ThreeResults(0)
Result2 = ThreeResults(1)
Result3 = ThreeResults(2)
UserAnswer = DisplayResults(UserTokens, UserAnswer, Result1, Result2, Result3)
Loop
End Sub
Function ValidateTokens(ByVal UserTokens)
Dim dblUserTokens As Double
Do Until IsNumeric(UserTokens)
Console.Write("Sorry you did not enter a valid number. Please try again. ")
UserTokens = Console.ReadLine()
Loop
'Make sure the user entered in a positive number
dblUserTokens = CDbl(UserTokens)
Do Until dblUserTokens > 0
Console.Write("Sorry you did not enter in a positive number. Please try again. ")
UserTokens = Console.ReadLine()
'Make sure the user entered in a number
Do Until IsNumeric(UserTokens)
Console.Write("Sorry you did not enter a valid number. Please try again. ")
UserTokens = Console.ReadLine()
Loop
dblUserTokens = CDbl(UserTokens)
Loop
Return UserTokens
End Function
Function GenerateNumbers()
Dim results(2) As String
Dim names(5) As String
Dim x As Integer
names(0) = "Cherries"
names(1) = "Oranges"
names(2) = "Plums"
names(3) = "Bells"
names(4) = "Melons"
names(5) = "Bar"
For x = 0 To 2
results(x) = names(CInt(Int((5 * Rnd()) + 1)))
Next x
Return results
End Function
Function DisplayResults(ByRef UserTokens, ByVal UserAnswer, ByRef number1, ByRef number2, ByRef number3)
Console.WriteLine("*** " & number1 & " ** " & number2 & " ** " & number3 & " ***")
If UserTokens > 0 Then
Console.WriteLine("You have " & UserTokens & " tokens left, do you want to play again? (yes or no)")
UserAnswer = (Console.ReadLine())
Else
Console.WriteLine("Sorry, you lost all of your tokens!")
End If
Return UserAnswer
End Function
End Module
|
Having trouble with function pointers and array
By : user4369812
Date : March 29 2020, 07:55 AM
may help you . I am currently using Visual Studios for class and needless to say I am having difficulty understanding pointers. I have created a program but does not seem to work right for me. I keep getting an assertion error after I click the function type that I want. I get a Debug assertion failed pop up error. Expression: result_pointer != nullptr. It says line 1558 , This is why your code fails: code :
scanf_s("%d", choice);
scanf_s("%d", &choice);
|
JavaScript: Creating a function to reject array elements found to be truthy, trouble with values in objects in the array
By : Zelka
Date : March 29 2020, 07:55 AM
around this issue Here's the solution I ended up with. To clarify, the tests were passing in arrays and objects, so that's why I first had trouble (with the objects) and then there was some confusion in in the answers. I wrote: code :
function reject(collection, callback) {
if(Array.isArray(collection)){
for (var i = 0; i < collection.length; i++) {
if(callback(collection[i]) === true){
collection.splice(i, 1);
}
}
} else {
for (number in collection){
if(callback(collection[number]) === true){
delete collection[number];
}
}
};
return collection;
}
|
I'm having trouble in C++ geting input from a user in a function, adding to an array, and printing that array
By : S.C.J
Date : March 29 2020, 07:55 AM
|