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