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?
36 Replies
Just iterate over the array like you did before and compare each number to your slump
also is there a way to make it so that this part goes up by 1 everytime its repeated ?
like write number 1
then write number 2
ohhh
thanks!
Use your variable that you use for the array index
thanks man but how do i compare each number?
FYI comparison is
==
not =
yeah i was testing
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
why does the i in tennnumbers[i] become red if i do so?
not only that becomes red rip
show me a screenshot?
oh nevermind i didnt put the $
but for all red squigglies, look at the bottom - you should have a nice error listing there
what does the $ do?
activate string interpolation
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
thanks !
its highly recommended to use this instead of
+
to "build" stringsdo you know a way to do this?
I believe ZZZZZZZZZZZ already told you
==
is for comparison, not =
but it doesnt work either way
Or, more precisely,
==
is for checking equalitytrue
i cant compare them
What does the error tell you?
tennumbers
is an array
you cant compare an array to a numberis there a way to compare its values?
Yes
Loop over the array
And check each element
not sure what you mean
Exactly what I said
think about it. You have 10 numbers.
Check first element
And second
And third
Fourth
how do you compare them to a single number?
Fifth
do i use tennumbers[1, 2, 3..] and so on?
In a loop, yes
Or you use a
foreach
loop
Whichever floats your boatokay im gonna try
thanks for your help
i did it thanks guys
Anytime :Ok: