C
C#10mo ago
levia_tano

beginner, two questions about arrays and counting?

hey so im trying to make a bingo like game where the user has to write 10 numbers in an array and if one of these numbers is the number who was randomly generated it has to say bingo, but i dont know how do the last part where i compare the numbers in the array to the randomly generated number any help please?
No description
36 Replies
Plerx
Plerx10mo ago
Just iterate over the array like you did before and compare each number to your slump
levia_tano
levia_tanoOP10mo ago
also is there a way to make it so that this part goes up by 1 everytime its repeated ?
No description
levia_tano
levia_tanoOP10mo ago
like write number 1 then write number 2 ohhh thanks!
Plerx
Plerx10mo ago
Use your variable that you use for the array index
levia_tano
levia_tanoOP10mo ago
thanks man but how do i compare each number?
Angius
Angius10mo ago
FYI comparison is == not =
levia_tano
levia_tanoOP10mo ago
yeah i was testing
Pobiega
Pobiega10mo ago
Console.WriteLine($"Write number {i+1}"); this uses a much nicer syntax for creating strings called "string interpolation" and to make the number go up, we can use the counter we already have: i
levia_tano
levia_tanoOP10mo ago
why does the i in tennnumbers[i] become red if i do so? not only that becomes red rip
Pobiega
Pobiega10mo ago
show me a screenshot?
levia_tano
levia_tanoOP10mo ago
oh nevermind i didnt put the $
Pobiega
Pobiega10mo ago
but for all red squigglies, look at the bottom - you should have a nice error listing there
levia_tano
levia_tanoOP10mo ago
what does the $ do?
levia_tano
levia_tanoOP10mo ago
thanks !
Pobiega
Pobiega10mo ago
its highly recommended to use this instead of + to "build" strings
levia_tano
levia_tanoOP10mo ago
do you know a way to do this?
Pobiega
Pobiega10mo ago
I believe ZZZZZZZZZZZ already told you == is for comparison, not =
levia_tano
levia_tanoOP10mo ago
but it doesnt work either way
Angius
Angius10mo ago
Or, more precisely, == is for checking equality
Pobiega
Pobiega10mo ago
true
levia_tano
levia_tanoOP10mo ago
i cant compare them
No description
Angius
Angius10mo ago
What does the error tell you?
Pobiega
Pobiega10mo ago
tennumbers is an array you cant compare an array to a number
levia_tano
levia_tanoOP10mo ago
is there a way to compare its values?
Angius
Angius10mo ago
Yes Loop over the array And check each element
levia_tano
levia_tanoOP10mo ago
not sure what you mean
Angius
Angius10mo ago
Exactly what I said
Pobiega
Pobiega10mo ago
think about it. You have 10 numbers.
Angius
Angius10mo ago
Check first element And second And third Fourth
Pobiega
Pobiega10mo ago
how do you compare them to a single number?
Angius
Angius10mo ago
Fifth
levia_tano
levia_tanoOP10mo ago
do i use tennumbers[1, 2, 3..] and so on?
Angius
Angius10mo ago
In a loop, yes Or you use a foreach loop Whichever floats your boat
levia_tano
levia_tanoOP10mo ago
okay im gonna try thanks for your help i did it thanks guys
Angius
Angius10mo ago
Anytime :Ok:
Want results from more Discord servers?
Add your server