C
C#9mo 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
Plerx9mo ago
Just iterate over the array like you did before and compare each number to your slump
levia_tano
levia_tano9mo 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_tano9mo ago
like write number 1 then write number 2 ohhh thanks!
Plerx
Plerx9mo ago
Use your variable that you use for the array index
levia_tano
levia_tano9mo ago
thanks man but how do i compare each number?
Angius
Angius9mo ago
FYI comparison is == not =
levia_tano
levia_tano9mo ago
yeah i was testing
Pobiega
Pobiega9mo 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_tano9mo ago
why does the i in tennnumbers[i] become red if i do so? not only that becomes red rip
Pobiega
Pobiega9mo ago
show me a screenshot?
levia_tano
levia_tano9mo ago
oh nevermind i didnt put the $
Pobiega
Pobiega9mo ago
but for all red squigglies, look at the bottom - you should have a nice error listing there
levia_tano
levia_tano9mo ago
what does the $ do?
levia_tano
levia_tano9mo ago
thanks !
Pobiega
Pobiega9mo ago
its highly recommended to use this instead of + to "build" strings
levia_tano
levia_tano9mo ago
do you know a way to do this?
Pobiega
Pobiega9mo ago
I believe ZZZZZZZZZZZ already told you == is for comparison, not =
levia_tano
levia_tano9mo ago
but it doesnt work either way
Angius
Angius9mo ago
Or, more precisely, == is for checking equality
Pobiega
Pobiega9mo ago
true
levia_tano
levia_tano9mo ago
i cant compare them
No description
Angius
Angius9mo ago
What does the error tell you?
Pobiega
Pobiega9mo ago
tennumbers is an array you cant compare an array to a number
levia_tano
levia_tano9mo ago
is there a way to compare its values?
Angius
Angius9mo ago
Yes Loop over the array And check each element
levia_tano
levia_tano9mo ago
not sure what you mean
Angius
Angius9mo ago
Exactly what I said
Pobiega
Pobiega9mo ago
think about it. You have 10 numbers.
Angius
Angius9mo ago
Check first element And second And third Fourth
Pobiega
Pobiega9mo ago
how do you compare them to a single number?
Angius
Angius9mo ago
Fifth
levia_tano
levia_tano9mo ago
do i use tennumbers[1, 2, 3..] and so on?
Angius
Angius9mo ago
In a loop, yes Or you use a foreach loop Whichever floats your boat
levia_tano
levia_tano9mo ago
okay im gonna try thanks for your help i did it thanks guys
Angius
Angius9mo ago
Anytime :Ok:
Want results from more Discord servers?
Add your server