r/csharp • u/Ok_Breadfruit5793 • 2d ago
Showcase Man tries coding for the first time, ends up making gambling code
Pretty self explanatory. I tried C# and after some goofing around made this.
169
Upvotes
18
u/Prima13 1d ago
Nice job. This is more or less how we all started. In my case it was on a Timex Sinclair 1000 in line numbered BASIC in 1983.
As others have mentioned, your if statement could be reduced to just:
if(randomNumber < 6) {// do something}else {// do something else}6
u/astraseeker 1d ago
Brother learns coding raw like in the good old days (in 2021)
2
u/Panderz_GG 1d ago edited 1d ago
Very nice, people already talked about the numbers.
Now to make this program a little bit more involved.
What can you do with the string you just got?
You want the User to put in the string "Casino" but your program actually doesn't care what the User writes, even if they put in "Trololo" the program will generate a random number, IF you could find a way to COMPARE strings and let your program respond accordingly, that would be cool. Maybe have it ask for the correct string WHILE the incorrect string is saved in the string variable.
138
u/rupertavery64 2d ago edited 2d ago
Great! Now think about what all the numbers 1,2,3,4,5 and 6,7,8,9 have in common. And think about the operators ==, <, >, <=, >=
How can you describe the numbers 1 through 5 in relation to the
randomNumberusing one of those operators? Can you write it in such a way that you don't have to write each number?BTW, what you've done is exactly what everyone who doesn't follow a tutorial does - goof around with code. Have fun. It's a proven way to learn, it's what we do as kids.
31
u/TheKidfromVillage 2d ago
This kinda reminds me of my early programming days😂. Keep it up. Try building unconventional projects, there you'll end up learning a lot.
11
u/CalebAsimov 1d ago
Now you're ready for this obligatory xkcd: https://xkcd.com/221/
6
u/zhouluyi 1d ago
Some 30+ years ago I had the huge insight of checking for odd or even in an integer, by dividing by two, converting to string and finding a '.' between the numbers.
4
u/Narrow-Low-3137 1d ago
Good work man. keep at it. Good on you for actually trying to learn vs just prompting an ai 👏
4
u/Rrrrry123 1d ago
W code, bro, fr fr.
3
u/MeLittleThing 1d ago
Your code is working, that's what matters, especially for an early beginner. It could be greatly improved, of course, but you'll find it yourself over time, with practice and experience
1
u/thygrrr 1d ago
Literally my first random number "generator" was a fixed list of print statements, in an endless loop, that I would interrupt with AMIGA+. ("Ctrl-C")
You're good.
1
u/soundwave_sc 1d ago
This is a good start, but you do know as the house - nothing is ever random.
Try rigging your own outcomes, enjoy the process.
1
u/NecoDev 1d ago
You know, operators that are not == DO exist.
Conditional operators ALSO exist.
0
u/Sad-Sun4611 1d ago
" if random number equals 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9"
Lol, lmao even.
-1
u/redwirelessmouse 1d ago
bussin'