C
C#12mo ago
Array

Can someone explain to me what a bool is and how I can implement it in other data structures?

Pretty much title, I'm trying to code a simple game in C# and my teacher suggested I use booleans to make a certain statement come up given if the boolean was true, can someone explain to me how it works?
340 Replies
Array
ArrayOP12mo ago
Thank you so much JP! I've just been learning computer science and I won''t lie it has been a bit tricky to start off @JP thanks for trying to help me out
Array
ArrayOP12mo ago
@JP Hi, sorry to ping, but can you explain this to me?
No description
Array
ArrayOP12mo ago
What is GetType()); ? Is it just saying theyre boolean values?
JP
JP12mo ago
yes!
Array
ArrayOP12mo ago
Could you use this command for any other data types like int too?
JP
JP12mo ago
GetType() is a function available on every type to let you know what it is yes! I always have a blank c# console app project open when reading through examples so I can run their examples and make changes to see how it works makes learning more interactive, and easier to check these things imo
Array
ArrayOP12mo ago
Thanks for the suggestion
Array
ArrayOP12mo ago
@JP Sorry to ping again, but is this converting it into a bool data type?
No description
Array
ArrayOP12mo ago
I know Parse converts stuff
JP
JP12mo ago
Yep, this is another way to do that type of conversion Convert is a static class that has a lot of ways to do a variety of types of conversions
Array
ArrayOP12mo ago
Gotcha I was thinking, maybe what he meanto to convert it to a bool was to parse the event I want to occur and then change it to a Bool? Up until now I have only used Parse commands though
JP
JP12mo ago
have you ever used if statements? (and did you get to the section on boolean expressions in that article?
Array
ArrayOP12mo ago
Sorry if I am being vague I am new to this and have been really struggling for a while Ya, I am trying to make an if statement to represent the course of action I wanna use
JP
JP12mo ago
sounds like a good plan
Array
ArrayOP12mo ago
Once again sorry if I sound really dumb or if this is easy I am just figuring it out really sorry
JP
JP12mo ago
I imagine that is what they meant. Inside an if statement, if (x > 5) the x > 5 bit is called a "boolean expression" you're chillin, dw so, where are you at right now. Do you have a plan, or still figuring it out? Feel free to drop your current code here and we can take a look
Array
ArrayOP12mo ago
I can drop my current code one second
JP
JP12mo ago
sidenote, this is useful for formatting: $code
MODiX
MODiX12mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Array
ArrayOP12mo ago
https://paste.mod.gg/cmtsumueoivd/0 @JP I inputted here if you wanna see
BlazeBin - cmtsumueoivd
A tool for sharing your source code with the world!
Angius
Angius12mo ago
Looks like it would work
JP
JP12mo ago
looks like ya got cut off:
No description
Array
ArrayOP12mo ago
I'm having an issue with my if statements and an actual variable for the events of winning and losing Pretty much I want the loop to finish or stop if the user wins or loses, but I am not sure how to do that as I thought when a loop end it can only have 1 condition
Angius
Angius12mo ago
You can break; out of the loop
Array
ArrayOP12mo ago
He suggested I create booleans for those events for the loop
JP
JP12mo ago
yeah, that's also possible
Angius
Angius12mo ago
That's also possible, yeah Great minds think alike lmao
JP
JP12mo ago
indeed
Angius
Angius12mo ago
bool run = true;
while (run)
{
// do stuff
if (something)
{
run = false;
}
}
bool run = true;
while (run)
{
// do stuff
if (something)
{
run = false;
}
}
I assume that's what you mean
JP
JP12mo ago
hah, ya beat me. Yeah, this ^
Array
ArrayOP12mo ago
Ya, so for the game it would be loop again if they lost, and the loop would end if they won or lost, and I'd have to writeline a message
JP
JP12mo ago
then something is your win condition
Array
ArrayOP12mo ago
Ya that makes sense, what is throwing me off is that I have 2 conditions to end the loop (sorry if I sound confusing I was really struggling)
JP
JP12mo ago
you can combine boolean expressions with things called logical operators
Array
ArrayOP12mo ago
Ya, I was thinking maybe I ccould make booleans to show that if your dices roll to 7 or 11 you win, or if you role a double, loss Oh yeah!
Angius
Angius12mo ago
bool run = true;
while (run)
{
// do stuff
if (won)
{
Console.WriteLine("Yippe!");
run = false;
}
else if (lost)
{
Console.WriteLine("Sucker!");
run = false;
}
}
bool run = true;
while (run)
{
// do stuff
if (won)
{
Console.WriteLine("Yippe!");
run = false;
}
else if (lost)
{
Console.WriteLine("Sucker!");
run = false;
}
}
JP
JP12mo ago
these let you say things like if hasWon AND isFirstTurn (do something) in c# AND is && and or is ||
Angius
Angius12mo ago
And yeah, you can use boolean operators
Array
ArrayOP12mo ago
This makes sense thanks so much for the help guys i was very lost i am new to computer science but i really like math so i thought i could try it out right now its hard for me but its fun and im learning slowlu I have a question about this technique If I have a loop and have a conditional operator for both when the loop ends how would I specify if they won or lost?
Angius
Angius12mo ago
The loop would end when the condition is false It runs as long as the condition is true
JP
JP12mo ago
store it in a bool?
Angius
Angius12mo ago
&& | A | B
A | T | F
B | F | F
&& | A | B
A | T | F
B | F | F
Array
ArrayOP12mo ago
What would the condition be in this case? If they got neither? The loop would only run if they neither won or lost
JP
JP12mo ago
bool hasWon = false;
while(/*your condition*/) {
// game code
if (/* win condition*/) {
hasWon = true;
// otherstuff
}
// otherstuff
}
bool hasWon = false;
while(/*your condition*/) {
// game code
if (/* win condition*/) {
hasWon = true;
// otherstuff
}
// otherstuff
}
Angius
Angius12mo ago
The condition can be simply named run If they won, set it to false If they lost, set it to false If they neither won nor lost, keep it as true, don't change it
Array
ArrayOP12mo ago
So here, you have a true or false value named hasWon set to false, I'm a little confused though, the loop runs if hasWon is true, shouldn't it be flipped since I want the loop to end when they win
Angius
Angius12mo ago
The loop runs as long as the condition inside is true You can use boolean operators to your hear's content You can use !hasWon to negate it, so the loop runs as long as the player has not won
JP
JP12mo ago
the while condition there is a comment, I didn't fill that in for the example here, let's try this
Array
ArrayOP12mo ago
Sorry if this is another dumb question, but how does the condition run occupy both winning and losing if they are different events?
Angius
Angius12mo ago
You can set run to false no matter if the player won or lost
JP
JP12mo ago
this is how
Array
ArrayOP12mo ago
sorry if this is dumb again, but was it setting run to false really doing in the code?
Angius
Angius12mo ago
It makes the loop stop Because it runs as long as run is true If run becomes false, the loop stops
MODiX
MODiX12mo ago
Angius
REPL Result: Success
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 10)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 10)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
Console Output
You lost with 4
You lost with 4
Compile: 665.310ms | Execution: 51.054ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
Well that was a fast loss lmao
MODiX
MODiX12mo ago
Angius
REPL Result: Success
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 10)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 10)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
Console Output
You lost with 5
You lost with 5
Compile: 575.298ms | Execution: 90.075ms | React with ❌ to remove this embed.
JP
JP12mo ago
hah
MODiX
MODiX12mo ago
Angius
REPL Result: Success
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 5)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 5)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
Console Output
You won with 93!
You won with 93!
Compile: 601.550ms | Execution: 89.028ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
And a fast win lol
MODiX
MODiX12mo ago
Angius
REPL Result: Success
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 10)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
bool run = true;
while (run)
{
var rand = Random.Shared.Next(0, 100);
if (rand > 80)
{
Console.WriteLine($"You won with {rand}!");
run = false;
}
else if (rand < 10)
{
Console.WriteLine($"You lost with {rand}");
run = false;
}
else
{
Console.WriteLine($"You got {rand}, try again!");
}
}
Console Output
You got 29, try again!
You won with 98!
You got 29, try again!
You won with 98!
Compile: 660.657ms | Execution: 92.428ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
Finally it ran more than once KEKW
Array
ArrayOP12mo ago
LOL Okay give me a sec to read and try to understand sorry guys if im asking repitive questions im just really trying to understand since it is hard for me i really appreciate you guys taking the time to help \ really tho
Angius
Angius12mo ago
It's a help channel, you're supposed to ask questions lol
Array
ArrayOP12mo ago
Starting to make some sense! so it is like reverse logic What would a good name for the bool be?
Angius
Angius12mo ago
run seems fine to me runGame maybe
Array
ArrayOP12mo ago
I have another question, within my if statement, what would be the correct way to represent what happens in a win or lose For a win in this game, you either get a 7 or 11 I created a variable for the dice RolledDice int RolledDice = RandGenerator.Next(1, 7); Could I say RolledDice = 7 OR 11 using a conditional operator or hmm maybe not 11
Angius
Angius12mo ago
rolledDice == 7 || rollDuce == 11
Array
ArrayOP12mo ago
it won't roll 11 it has to add to 7 or 11 sorry Is there a way to track the past 2 dice rolls outcome?
Angius
Angius12mo ago
sum == 7 || sum == 11
Array
ArrayOP12mo ago
Sorry again if this is a stupid question, what is sum? I know what a sum is but is it a special keyword in # C#
Angius
Angius12mo ago
Sum of the two rolls
MODiX
MODiX12mo ago
Angius
REPL Result: Success
bool run = true;
while (run)
{
var rollOne = Random.Shared.Next(0, 100);
var rollTwo = Random.Shared.Next(0, 100);
var sum = rollOne + rollTwo;

if (sum > 180)
{
Console.WriteLine($"You won with {sum}!");
run = false;
}
else if (sum < 10)
{
Console.WriteLine($"You lost with {sum}");
run = false;
}
else
{
Console.WriteLine($"You got {sum}, try again!");
}
}
bool run = true;
while (run)
{
var rollOne = Random.Shared.Next(0, 100);
var rollTwo = Random.Shared.Next(0, 100);
var sum = rollOne + rollTwo;

if (sum > 180)
{
Console.WriteLine($"You won with {sum}!");
run = false;
}
else if (sum < 10)
{
Console.WriteLine($"You lost with {sum}");
run = false;
}
else
{
Console.WriteLine($"You got {sum}, try again!");
}
}
Console Output
You got 60, try again!
You got 175, try again!
You got 55, try again!
You got 95, try again!
You got 35, try again!
You got 98, try again!
You got 121, try again!
You got 66, try again!
You got 110, try again!
You got 115, try again!
You got 131, try again!
You got 108, try again!
You got 150, try again!
You got 116, try again!
You got 116, try again!
You got 127, try again!
You got 61, try again!
You got 82, try again!
You got 69, try again!
You got 164, try again!
You got 92, try again!
You got 117, try again!
You got 40, try again!
You got 96, try again!
You got 138, try again!
You got 36, try again!
You got 24, try again!
You got 140, try again!
You got 91, try again!
You got 132, try again!
You got 110, try again!
You got 154, try again!
You got 148, try again!
You got 87, try again!
You got 137, try again!
You got 99, try again!
You got 39, try again!
You got 108, try again!
You got 122, try again!
You got 150, try again!
You got 69, try again!
You got 169, try again!
You got 54,
You got 60, try again!
You got 175, try again!
You got 55, try again!
You got 95, try again!
You got 35, try again!
You got 98, try again!
You got 121, try again!
You got 66, try again!
You got 110, try again!
You got 115, try again!
You got 131, try again!
You got 108, try again!
You got 150, try again!
You got 116, try again!
You got 116, try again!
You got 127, try again!
You got 61, try again!
You got 82, try again!
You got 69, try again!
You got 164, try again!
You got 92, try again!
You got 117, try again!
You got 40, try again!
You got 96, try again!
You got 138, try again!
You got 36, try again!
You got 24, try again!
You got 140, try again!
You got 91, try again!
You got 132, try again!
You got 110, try again!
You got 154, try again!
You got 148, try again!
You got 87, try again!
You got 137, try again!
You got 99, try again!
You got 39, try again!
You got 108, try again!
You got 122, try again!
You got 150, try again!
You got 69, try again!
You got 169, try again!
You got 54,
Compile: 572.403ms | Execution: 89.489ms | React with ❌ to remove this embed.
Array
ArrayOP12mo ago
Oh okay So I needed to create a variable for sum Ohhhhh So I actually needed to create 2 dice variables oh okay Dang I didn’t know you could name things DiceOne and DiceTwo I thought there was a way to track it in one variable
Angius
Angius12mo ago
Well, you could just do
var sum = Random.Shared.Next(1, 7) + Random.Shared.Next(1, 7);
var sum = Random.Shared.Next(1, 7) + Random.Shared.Next(1, 7);
directly Or you could store them in an array
var rolls = [ Random.Shared.Next(1, 7), Random.Shared.Next(1, 7) ];
var sum = rolls[0] + rolls[1];
var rolls = [ Random.Shared.Next(1, 7), Random.Shared.Next(1, 7) ];
var sum = rolls[0] + rolls[1];
Array
ArrayOP12mo ago
Haha my name is Arrays I haven’t learned Arrays yet in detail though Is Sum an int Variable?
Angius
Angius12mo ago
Yeah
bool run = true;
while (run)
{
int rollOne = Random.Shared.Next(0, 100);
int rollTwo = Random.Shared.Next(0, 100);
int sum = rollOne + rollTwo;

if (sum > 180)
{
Console.WriteLine($"You won with {sum}!");
run = false;
}
else if (sum < 10)
{
Console.WriteLine($"You lost with {sum}");
run = false;
}
else
{
Console.WriteLine($"You got {sum}, try again!");
}
}
bool run = true;
while (run)
{
int rollOne = Random.Shared.Next(0, 100);
int rollTwo = Random.Shared.Next(0, 100);
int sum = rollOne + rollTwo;

if (sum > 180)
{
Console.WriteLine($"You won with {sum}!");
run = false;
}
else if (sum < 10)
{
Console.WriteLine($"You lost with {sum}");
run = false;
}
else
{
Console.WriteLine($"You got {sum}, try again!");
}
}
Here's the same code with explicit types, if that helps
Array
ArrayOP12mo ago
For the double event, would it work to have another variable could double setting them equal?
Angius
Angius12mo ago
?
Array
ArrayOP12mo ago
Oh Sorry In the game you lose if you roll 2 of the same number Or a double
Angius
Angius12mo ago
rollOne == rollTwo then
Array
ArrayOP12mo ago
So like int Double = RollOne =RollTwo?
Angius
Angius12mo ago
No, this would be the loss condition
Array
ArrayOP12mo ago
Oh
Angius
Angius12mo ago
bool run = true;
while (run)
{
int rollOne = Random.Shared.Next(0, 100);
int rollTwo = Random.Shared.Next(0, 100);
int sum = rollOne + rollTwo;

if (sum > 180)
{
Console.WriteLine($"You won with {sum}!");
run = false;
}
else if (rollOne == rollTwo) // <--- here
{
Console.WriteLine($"You lost with {rollOne} and {rollTwo}");
run = false;
}
else
{
Console.WriteLine($"You got {sum}, try again!");
}
}
bool run = true;
while (run)
{
int rollOne = Random.Shared.Next(0, 100);
int rollTwo = Random.Shared.Next(0, 100);
int sum = rollOne + rollTwo;

if (sum > 180)
{
Console.WriteLine($"You won with {sum}!");
run = false;
}
else if (rollOne == rollTwo) // <--- here
{
Console.WriteLine($"You lost with {rollOne} and {rollTwo}");
run = false;
}
else
{
Console.WriteLine($"You got {sum}, try again!");
}
}
Array
ArrayOP12mo ago
Would I have to create a variable for that how would that work? Oh okay
Angius
Angius12mo ago
You can, but you don't have to
Array
ArrayOP12mo ago
Thanks for being patient with me I’m learning slowly One thing I realized is that you used a while loop here and I used a do while loop here, I’m curious on how I could adjust this into still using a do while loop My teacher had a lab where he made a guess game do the while statement ran the loop only if a condition wasn’t met Does the while statement of a do while loop always have to have a condition?
Angius
Angius12mo ago
The only difference between while and do..while is that the latter will run at least once
MODiX
MODiX12mo ago
Angius
REPL Result: Success
while (false)
{
Console.WriteLine("While");
}

do
{
Console.WriteLine("Do While");
}
while (false);
while (false)
{
Console.WriteLine("While");
}

do
{
Console.WriteLine("Do While");
}
while (false);
Console Output
Do While
Do While
Compile: 483.034ms | Execution: 68.235ms | React with ❌ to remove this embed.
Array
ArrayOP12mo ago
Wdym by at least once?
Angius
Angius12mo ago
This
Array
ArrayOP12mo ago
Wait, what is happening here? I see two different loops but only one is outputted What happened to the while?
Angius
Angius12mo ago
The condition was false so it did not execute The condition is checked where you see it, going top to bottom So while checks the condition first, then decides whether to execute the code inside or not In this case, condition was false from the get-go, so it didn't even execute the loop once do..while executes code first, then checks the condition to see if it should proceed to the next execution So it executed the code, then checked the condition, and since it was false it decided to not execute the next iteration
Array
ArrayOP12mo ago
Oh okay Oh okay So a do while runs it first While a while doesn’t
Angius
Angius12mo ago
Yep While checks, then runs Do...while runs, then checks
Array
ArrayOP12mo ago
Why is it double equals sign btw?
Array
ArrayOP12mo ago
Why do I get an error here?
No description
Array
ArrayOP12mo ago
@JP @ZZZZZZZZZZZZZZZZZZZZZZZZZ any ideas here?
JP
JP12mo ago
= is assignment == is equality check
Array
ArrayOP12mo ago
Also I'm a little confused one if I should set my if statement's condition to win or loss or if I should do like, on my do loop for the game Oh okay
Array
ArrayOP12mo ago
I still get an error
No description
JP
JP12mo ago
additionally, there is no left-hand side of your second condition || can only OR things that evaluate to booleans
Array
ArrayOP12mo ago
oh okay
JP
JP12mo ago
think of it like you currently have this: (Sum equals 7) OR (___ equals 11)
Array
ArrayOP12mo ago
So Sum on both sides!
JP
JP12mo ago
exactly!
Array
ArrayOP12mo ago
thank you I have a question about the Run Game bool i made should I make it at the end of my while loop
JP
JP12mo ago
try it!
Array
ArrayOP12mo ago
I'm a bit confused because I worry that if I put it at the end the game will go back to the main menu Oh okay
JP
JP12mo ago
see what happens! break things! See how it behaves. then, if stuck, give me a ping
Array
ArrayOP12mo ago
Okay thanks Is this an okay mindset to have?
JP
JP12mo ago
works well for me lol
Array
ArrayOP12mo ago
Sometimes I worry if I break things I won't able to fix them or I'm doing it wrong because coding is supposed to be "logical"
JP
JP12mo ago
I'm 90% learning by trial and error and scattered googling
Array
ArrayOP12mo ago
Ya I have this mindset too i just worry its bad
JP
JP12mo ago
and reading error messages the compiler spits at me ig lol the way I see it, if a broke it, you can usually fix it, might just take some time
Array
ArrayOP12mo ago
That's really encouraging to hear lol
JP
JP12mo ago
unless you're deleting files
Array
ArrayOP12mo ago
righttt
JP
JP12mo ago
becareful with accidentally deleting things but that's not what we're doing :P
Array
ArrayOP12mo ago
One thing I realize is that I always get the same two numbers, any reason why? @JP
No description
JP
JP12mo ago
I'd need to see your current code to know
Array
ArrayOP12mo ago
For sure! One moment
Array
ArrayOP12mo ago
BlazeBin - eehjowfuqzzm
A tool for sharing your source code with the world!
JP
JP12mo ago
you are doing the rolls before the loop so you store the values as your first step, then check those same stored values over and over in the loop you'd want to store those rolled values as the first step inside the loop, not before it
Array
ArrayOP12mo ago
Oh okay!
JP
JP12mo ago
probably near where you say "Enter Any Key to ROLL your 1st die"
Array
ArrayOP12mo ago
Thanks it worked! I'm really thankful for your help Have a question but... trying to understand something
JP
JP12mo ago
fire away
Array
ArrayOP12mo ago
When I get a win or loss, my program just returns to the menu. It doesn't super fast and doesn't show the winning message from the if else statements
JP
JP12mo ago
e.g you never see "CONGRATS!!! THESE TWO ROLLS SUM TO 11, YOU WON"?
Array
ArrayOP12mo ago
Here’s an example
Array
ArrayOP12mo ago
Yeah!
JP
JP12mo ago
aha, I understand so it looks like everything was cleared from the console do you see anywhere that could be happening? (sidenote, brb)
Array
ArrayOP12mo ago
No worries! I see I added a Console.Clear but I’m not 100% how that works yet
JP
JP12mo ago
Experiment! What happens if you comment it out for now
Array
ArrayOP12mo ago
I realized that the Console.Clear in the if statement after the menu works to clear the menu away, I commented it out, but the menu remains and takes up space while the issue still exists I have a question about the Console clear, how does it work or on what basis does it clear things? Is it just the ones ahead of it/ that have Console wihin them
JP
JP12mo ago
note, there is more than one Console.Clear() in your app!
Array
ArrayOP12mo ago
Ohhh Yeah I have one within my menu Hm it is worth asking why I added that
JP
JP12mo ago
the other one might be causing your issue 😉 Console.Clear() will immediately clear anything that was printed before it gets run
Array
ArrayOP12mo ago
I have an idea to make the game more fun but I'm not 100% sure how to implement it I learned in class you can track the number of guesses per round using the counter Do you know for loops?
JP
JP12mo ago
ye though you don't need a for loop for a counter at it's core a "counter" is just an int variable that you add 1 to every time you want the "count" to go up
Array
ArrayOP12mo ago
My teacher did this
No description
No description
Array
ArrayOP12mo ago
Oh okay
JP
JP12mo ago
yep, exactly
Array
ArrayOP12mo ago
I see I want it to count until they get it right or lose
JP
JP12mo ago
"Guesses" is the int, and Guesses++ means "add one to Guesses"
Array
ArrayOP12mo ago
Although my difference is that I don't have an that they check Maybe I can make a variable for it Something like Rounds i GOT THE COUNTER to work but I have one issue, it doesn;t actually count the rounds or rather I don't know where to place it in my code to make it count... maybe after the loop?
JP
JP12mo ago
When do you want the count to go up?
Array
ArrayOP12mo ago
After the first two dice rolls
JP
JP12mo ago
put it there! (the adding to the count bit, not the definition for the count variable)
Array
ArrayOP12mo ago
right I will put Rounds++;
Array
ArrayOP12mo ago
I ran into this error, where I got the counter not increasing
No description
Array
ArrayOP12mo ago
Any ideas?
Array
ArrayOP12mo ago
No description
JP
JP12mo ago
let's see the code!
Array
ArrayOP12mo ago
Sure thing
Array
ArrayOP12mo ago
BlazeBin - bvydpcbtypno
A tool for sharing your source code with the world!
JP
JP12mo ago
alright, looking so, what happens in the first four lines of the dice-rolling loop, every time it runs? what does the computer do (in broad terms)
Array
ArrayOP12mo ago
I declared it’s variables, so it understands dice 1 and 2, sum and rounds to count So I gave RolledDiceOne a datatype of integer so it is a number And gave it to the random generator Similar for rolled DiceTwo And for Sum I gave it a combination of both Rounds I gave 0 so it starts at 0
JP
JP12mo ago
all true what happens on the second iteration of the loop? if unsure, just say, I can explain
Array
ArrayOP12mo ago
The second loop is to ask them to input something to play, and then give them a result
JP
JP12mo ago
When I say "the second iteration of the loop" I mean this same loop, the second time it runs
Array
ArrayOP12mo ago
Oh
JP
JP12mo ago
and the question was kind of a trick
Array
ArrayOP12mo ago
Doesn’t it loop again?
JP
JP12mo ago
the answer is "the same thing that happened the first time!" exactly, yes!
Array
ArrayOP12mo ago
Yay
JP
JP12mo ago
so, notably, it would get reset to 0 but there is actually a second part do you know what "variable scope" is? Fine if not, can explain quickly
Array
ArrayOP12mo ago
Ya that makes sense, would it be possible to track it still even if it loops? My teacher did but I’m not sure how ours is different Not sure Did it here
JP
JP12mo ago
I'll explain, "variable scope" plays a role, and its a good thing to know
Array
ArrayOP12mo ago
Oh ok Thanks
JP
JP12mo ago
so, "scope" is a term used to describe where a variable lives, and where it can be accessed from. "Blocks" (the areas in your code surrounded by curly { braces } are the primary thing that will determine the scope of a variable.
Array
ArrayOP12mo ago
What is a variable scope?
JP
JP12mo ago
example, because a picture is worth a thousand words:
string myName = "JP";

{ // open curly brace begins a new scope
string myUsername = "john_paul_r";
// fine
Console.WriteLine(myName);
// also fine
Console.WriteLine(myUsername);

} // close curly brace ends the scope, the variables declared inside are dropped, no longer accessible!

// still fine
Console.WriteLine(myName);
// error, myUsername cannot be accessed
// because it fell out of scope
// at the curly brace `}` earlier!
Console.WriteLine(myUsername);
string myName = "JP";

{ // open curly brace begins a new scope
string myUsername = "john_paul_r";
// fine
Console.WriteLine(myName);
// also fine
Console.WriteLine(myUsername);

} // close curly brace ends the scope, the variables declared inside are dropped, no longer accessible!

// still fine
Console.WriteLine(myName);
// error, myUsername cannot be accessed
// because it fell out of scope
// at the curly brace `}` earlier!
Console.WriteLine(myUsername);
any questions about this ^? feel free to toss in your IDE to see what errors it gives you
Array
ArrayOP12mo ago
One second let me it through sorry
JP
JP12mo ago
you're golden, take yer time
Array
ArrayOP12mo ago
Probably a dumb question but wdym by var? Like datatype?
JP
JP12mo ago
oh, var is a shortcut telling c# to guess the datatype in this case, it guesses "string" because the value on the right is a string literal (in other words a value between quotes like that is always a string) so it would be the same as me writing string in this case I'll change it to that to be more specific!
Array
ArrayOP12mo ago
Oh okay
JP
JP12mo ago
any questions about variable scope or the example above?
Array
ArrayOP12mo ago
What is being done with the myusername variable? string myusername = john paul e And “fine”
JP
JP12mo ago
in what sense? Are you asking what the code written is attempting to do, or what happens behind the scenes when the scope ends
Array
ArrayOP12mo ago
Attempting to do
JP
JP12mo ago
that's just a comment I included to note that the next line will not error
Array
ArrayOP12mo ago
Oh ok Do they mean the same thing?
JP
JP12mo ago
it's... being logged? Is that what you're asking? "they"?
Array
ArrayOP12mo ago
No description
JP
JP12mo ago
there are 6 lines to choose from there :P idk which you're referring to
Array
ArrayOP12mo ago
Do all the lines that aren’t header comments relate? Or are you just showing it I thought writeline needed “
JP
JP12mo ago
they do all relate, they are all one small program, yes Console.WriteLine can write any string strings can be stored in variables just like ints and bools and you can pass the variable that contains the string to WriteLine, and it will get the value contained within Just like you could do
5 + 3
5 + 3
or
int num1 = 5;
int num2 = 3;
num1 + num2
int num1 = 5;
int num2 = 3;
num1 + num2
and get the same result
Array
ArrayOP12mo ago
Oh okay
JP
JP12mo ago
here is an example of the output, and it's interactive, so you can fiddle around
MODiX
MODiX12mo ago
JP
sharplab.io (click here)
string myName = "JP";
{ // open curly brace begins a new scope
string myUsername = "john_paul_r";
// fine
Console.WriteLine(myName);
// also fine
Console.WriteLine(myUsername);
} // close curly brace ends the scope, the variables decla...
// still fine
Console.WriteLine(myName);
// 5 more lines. Follow the link to view.
string myName = "JP";
{ // open curly brace begins a new scope
string myUsername = "john_paul_r";
// fine
Console.WriteLine(myName);
// also fine
Console.WriteLine(myUsername);
} // close curly brace ends the scope, the variables decla...
// still fine
Console.WriteLine(myName);
// 5 more lines. Follow the link to view.
React with ❌ to remove this embed.
JP
JP12mo ago
if no immediate questions, I can relate this back to your program's count problem
Array
ArrayOP12mo ago
Hey,. i’m sorry I left yesterday, I feel asleep Ya, this makes sense It's like different ways to write the same thing as long as within the brackets I'm thinking my counter has to be within the lines of code containing where I want a round to be quanitied, and make sure it's within the brackets @ZZZZZZZZZZZZZZZZZZZZZZZZZ you helped me alot yesterday, any chance you can take a look at this too? Making I should put the counter at the bottom I tried this but it didn't work, I also added a play again function but I think I implemented it weirdly, I only want it to say that if a user wins or loses, not after the loop, so I'll put it in the statements where the user wins/loses
Array
ArrayOP12mo ago
BlazeBin - szpnjayemhit
A tool for sharing your source code with the world!
Array
ArrayOP12mo ago
No description
Array
ArrayOP12mo ago
One of my issues is that the play again doesn't recycle the loop, which makes it a bit hard, not sure how to fix that As you can see here I entered 1 but it just makes the whole thing restart which is wrong
SinFluxx
SinFluxx12mo ago
What do you mean "recycle the loop"?
Array
ArrayOP12mo ago
Sorry, I meant loop again I want it to be that if you press 1 it loops back to the two dice rolls, given you win or lose since the hame ends @SinFluxx Sorry if my wording is wacky Also thanks for even trying to help @ZZZZZZZZZZZZZZZZZZZZZZZZZ any chance you can help me out now if you're back online?
Angius
Angius12mo ago
I can try
Array
ArrayOP12mo ago
YAY thanks so much for responding I am very grateful omg
Angius
Angius12mo ago
So, if I'm not mistaken, you want to restart this particular game, not the whole application?
Array
ArrayOP12mo ago
Yes!!
Angius
Angius12mo ago
Meaning, you don't want to go back to game selection, you want to re-run the game of Craps, Multiplayer for example?
Array
ArrayOP12mo ago
Right! I want them to play again after they win or lose
Angius
Angius12mo ago
If so, the best way would be to enclose it in another loop
Array
ArrayOP12mo ago
Oh okay
Angius
Angius12mo ago
And with the code growing more complex like that, you might consider splitting it into separate methods
Array
ArrayOP12mo ago
I haven't learned about methods yet
Angius
Angius12mo ago
Ah, all in due time, then
Array
ArrayOP12mo ago
Amen!! I think it is our next unit in class I am very beginner so sorry if I am lost a bit but the help is thanked it takes time So, would I just made another do while loop within the do while loop?
Angius
Angius12mo ago
Yep
Array
ArrayOP12mo ago
Ok, I will try this out I'm gonna place it above the if statement for the first game
Angius
Angius12mo ago
var run = true;
while (run)
{
var input = Console.ReadLine();
switch (input)
{
case "craps":
var runGame = true;
while (runGame)
{
// ...
}
break;
case "craps multiplayer":
var runGame = true;
while (runGame)
{
// ...
}
// ...
}
}
var run = true;
while (run)
{
var input = Console.ReadLine();
switch (input)
{
case "craps":
var runGame = true;
while (runGame)
{
// ...
}
break;
case "craps multiplayer":
var runGame = true;
while (runGame)
{
// ...
}
// ...
}
}
Something like that, basically One overarching game loop, and smaller loops one per individual game
Array
ArrayOP12mo ago
Gotcha!! @ZZZZZZZZZZZZZZZZZZZZZZZZZ is it okay if I send you a link of my code? im stuck on where to start the do while loop within the other one i tried to frame it like this but it kinda broke up the brackets i tried to put it over my if statement but it doesnt really get the code in ill send you a link
Angius
Angius12mo ago
Sure
Array
ArrayOP12mo ago
BlazeBin - vosdoaldryun
A tool for sharing your source code with the world!
Array
ArrayOP12mo ago
I tried to put it above the line where it says "if menu == 1" Any suggestions on how I should try it I feel like alot of the time I do get the idea but I just really struggle implementing it without alot of errors or even like near breaking the whole thing
Angius
Angius12mo ago
Looks fine
Array
ArrayOP12mo ago
Ya, but I didn’t implement the do while loop within it I’m not sure where to put it or which line Without messing the other one within it
Angius
Angius12mo ago
I see you do have the inner loop What exactly is the issue with it?
Array
ArrayOP12mo ago
Ya but I removed the functionality to Play Again The press 1 to play again
JP
JP12mo ago
RunGame && PlayAgain == "1"
change this to
RunGame && PlayAgain != "1"
Array
ArrayOP12mo ago
I want to add that But I want them to press 1 to playagain
JP
JP12mo ago
oh, apologies, misreaed
Array
ArrayOP12mo ago
Ya
Angius
Angius12mo ago
It should just automatically play again unless you set RunGame to false
Array
ArrayOP12mo ago
I want to implement it so that if they win or lose they press 1 to play again
Angius
Angius12mo ago
So, check the input while inside of the inner loop
JP
JP12mo ago
before terminating the loop,
RunGame = RunGame || PlayAgain == "1";
RunGame = RunGame || PlayAgain == "1";
Array
ArrayOP12mo ago
Would that be the while statement? Like the condition of the do while
Angius
Angius12mo ago
var run = true;
while (run)
{
var runGame = true;
while (runGame)
{
Console.WriteLine("Play again? [y/n]");
runGame = Console.ReadLine() == "y";
}
}
var run = true;
while (run)
{
var runGame = true;
while (runGame)
{
Console.WriteLine("Play again? [y/n]");
runGame = Console.ReadLine() == "y";
}
}
That'd be a minimal example
JP
JP12mo ago
try it, I think that also works, yes
Array
ArrayOP12mo ago
Oh okay That looks like JP’s Too
JP
JP12mo ago
the ||` is the meaningful bit
Array
ArrayOP12mo ago
Is it correct to only ask them if they win or lose by putting it under the if and else if statements for winning and losing? Just making sure Imm doing it right
Angius
Angius12mo ago
You can, sure
Array
ArrayOP12mo ago
Also question, why do we set RunGame = to itself, and why is it and OR statement instead of AND?
JP
JP12mo ago
because, in the case where you neither won nor lost, you never asked them if they want to continue you presumably just want the game to continue going if RunGame is already true because they've not won/lost yet
RunGame = RunGame || PlayAgain == "1";
RunGame = RunGame || PlayAgain == "1";
Another way of writing this would be:
if (RunGame == false) {
RunGame = PlayAgain == "1";
}
if (RunGame == false) {
RunGame = PlayAgain == "1";
}
point being, we only care about PlayAgain if RunGame is false and RunGame is only false if they've won or lost
Array
ArrayOP12mo ago
What does the statement RunGame = RunGame by itself mean?
JP
JP12mo ago
on its own that just assigns the value currently stored in RunGame to RunGame. So it effectively does nothing as part of the larger expression, however:
RunGame = RunGame || PlayAgain == "1";
RunGame = RunGame || PlayAgain == "1";
if RunGame is already true, it'll never be set to false by this statement, because of the || because true || false -> true
Array
ArrayOP12mo ago
Why does true or False make false turn to true?
JP
JP12mo ago
read it like this: are true OR false true? if yes, return true, else return false that is what true || false means similarly, true && false asks: are true AND false true? If yes, return true, else return false so true && false yields false, since that question is not satisfied.
Array
ArrayOP12mo ago
“Are true or false true?” what do you mean by true (the one bolded)?
JP
JP12mo ago
I mean literally the value true true is true. false is not true.
Array
ArrayOP12mo ago
Oh okay Only true is true and false is not teue True Ok i think that makes a little bit more sense Its checking if its true Dont these do the same thing then?
JP
JP12mo ago
? elaborate
Array
ArrayOP12mo ago
Both of them check if true or false matches the value true, and if they match it returns true, if not it returns false
JP
JP12mo ago
are green and red green?
Array
ArrayOP12mo ago
No
JP
JP12mo ago
are green or green green?
Array
ArrayOP12mo ago
Yeah
JP
JP12mo ago
tada that's the difference
Array
ArrayOP12mo ago
Oh ok What happened to red I realized its and vs or though
JP
JP12mo ago
ah, gz I goofed my example restarting: are green and red green?
no
are green or red green?
Array
ArrayOP12mo ago
It can be green, for and it cannot be green only because its both
JP
JP12mo ago
i have no idea what you just said lmao
Array
ArrayOP12mo ago
Looool
JP
JP12mo ago
generally, AND needs all to match
Array
ArrayOP12mo ago
Im saying that green and red cant be just green because its both
JP
JP12mo ago
OR needs ANY (at least one) to match
Array
ArrayOP12mo ago
Green or red can be green sometimes But technically it can be red too Oh okay
JP
JP12mo ago
welp, I declare the example bad :P
Array
ArrayOP12mo ago
That makes sense then Well i get what you’re saying
JP
JP12mo ago
i'll have to get a better one next time lol
Array
ArrayOP12mo ago
It just needs one to match
JP
JP12mo ago
si
Array
ArrayOP12mo ago
U have no idea how much i appreciate this though 😭😭 At least i am starting to understand the logic a bit Gonna try running it but I implemented this
Array
ArrayOP12mo ago
This happens
No description
Array
ArrayOP12mo ago
So this is kinda bad because instead of looping again to roll, it brings the menu Let me try again to see what happens if you win @JP any ideas why this may happen?
JP
JP12mo ago
send code!
Array
ArrayOP12mo ago
Sure thing
Array
ArrayOP12mo ago
BlazeBin - gmgphwfrdich
A tool for sharing your source code with the world!
Array
ArrayOP12mo ago
Anything jump out?
JP
JP12mo ago
no.. this is odd experimenting
Array
ArrayOP12mo ago
Gotcha
JP
JP12mo ago
I have a suspicion move PlayAgain right before the while condition er, actually, right after the innermost do, forgot you read that in earlier in the loop point is, it needs to fall out of scope when the inner loop restarts
Array
ArrayOP12mo ago
By PlayAgain, which line of code are you referring to specifically? Is it String PlayAgain = string.Empty?
JP
JP12mo ago
I'm thinkin something like this
do {
string PlayAgain = string.Empty;

// game code here

RunGame = RunGame || PlayAgain == "1";
} while (RunGame);
do {
string PlayAgain = string.Empty;

// game code here

RunGame = RunGame || PlayAgain == "1";
} while (RunGame);
though I'm suddenly not 100% sure that's the problem, checking.. you are also not doing
PlayAgain = Console.ReadLine();
PlayAgain = Console.ReadLine();
in the Sum == 7 branch
Array
ArrayOP12mo ago
Oops Thank Fixed this That may have fixed it, will try it out
Array
ArrayOP12mo ago
IT WORKED
No description
Array
ArrayOP12mo ago
wow well let me try again I think that fixed it lol
Array
ArrayOP12mo ago
I think the only thing left to fix is the counter and the formating
No description
Array
ArrayOP12mo ago
I think a good idea is to clear the prior results As in like if you get neither win or loss, after a round is counted, it clears it off the screen thank you so much jp ill be back in a bit i need a break Alright I'm back Thank you so much for helping me out guys @JP @ZZZZZZZZZZZZZZZZZZZZZZZZZ I just want to do something I think will be a bit more minor but yeah I want to fix the counter, it's kinda buggy, it doesn't increment by 1 like I want it to it seems like it's always stuck at 1
Angius
Angius12mo ago
Anytime
Array
ArrayOP12mo ago
Thanks so much any idea on how to make the counter fixed? I remember yesterday JP was talking about scopes maybe I should put it within the bracketed if statements? I want it to increase by 1 every time 2 rolls happen or at least output that at the end, for some reason it doesn't work it just goes up by 1 it just stays at 1* any ideas on how i can fix this? @ZZZZZZZZZZZZZZZZZZZZZZZZZ dont mean to double ping but you were jus here
Angius
Angius12mo ago
$scopes
MODiX
MODiX12mo ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
Angius
Angius12mo ago
If you want something to persist outside of some given scope, it needs to be defined outside of that scope
Array
ArrayOP12mo ago
BlazeBin - oitamnrieqew
A tool for sharing your source code with the world!
Array
ArrayOP12mo ago
I put the counter after the if statements and made the int for it above it both of them are in the loop though im confused why its not increasing If it’s okay, can you check if everything is placed correctly? I assumed the do while loop is the “scope” here
Angius
Angius12mo ago
Declare the rounds outside of the loop With every loop, you create a new variable rounds And set it to 0
Array
ArrayOP12mo ago
When you say declare the variable, how do I declare it without setting it to 0?
MODiX
MODiX12mo ago
Angius
REPL Result: Success
var rounds = 0;
for (var i = 0; i < 5; i++)
{
rounds++;
}
Console.WriteLine($"You played {rounds} rounds");
var rounds = 0;
for (var i = 0; i < 5; i++)
{
rounds++;
}
Console.WriteLine($"You played {rounds} rounds");
Console Output
You played 5 rounds
You played 5 rounds
Compile: 641.111ms | Execution: 53.360ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
Declare it and set it to 0 But it has to be before the loop
Array
ArrayOP12mo ago
I tried that,got this error
No description
Angius
Angius12mo ago
Means you have a Rounds variable somewhere already Somewhere in the outer scope, specifically
Array
ArrayOP12mo ago
I see
Array
ArrayOP12mo ago
Look at this for exmaple
No description
No description
Array
ArrayOP12mo ago
I tried to mimmick what you did here Ooosp
Angius
Angius12mo ago
Seems fine
Array
ArrayOP12mo ago
No description
Array
ArrayOP12mo ago
So I decleared it outside the loop, within the loop set it to 0, then made it count by 1 each time I'll try running it to see if it counts
MODiX
MODiX12mo ago
Angius
REPL Result: Success
var rounds = 0;
for (var i = 0; i < 5; i++)
{
rounds++;
Console.WriteLine($"You played {rounds} rounds so far.");
}
Console.WriteLine($"You played {rounds} rounds in total!");
var rounds = 0;
for (var i = 0; i < 5; i++)
{
rounds++;
Console.WriteLine($"You played {rounds} rounds so far.");
}
Console.WriteLine($"You played {rounds} rounds in total!");
Console Output
You played 1 rounds so far.
You played 2 rounds so far.
You played 3 rounds so far.
You played 4 rounds so far.
You played 5 rounds so far.
You played 5 rounds in total!
You played 1 rounds so far.
You played 2 rounds so far.
You played 3 rounds so far.
You played 4 rounds so far.
You played 5 rounds so far.
You played 5 rounds in total!
Compile: 630.047ms | Execution: 93.792ms | React with ❌ to remove this embed.
Array
ArrayOP12mo ago
Oh it seems I made an error I have to put my counter inside the loop? the Rounds++? ok, ill try that well actually im confused @ZZZZZZZZZZZZZZZZZZZZZZZZZ I'm a bit confused where I should put my counter like its still within my loop and i ran it it doesnt increment by 1
Angius
Angius12mo ago
Look at my example The counter is outside of the loop And it gets incremented inside of the loop
Array
ArrayOP12mo ago
I’m a bit confused because I don’t have a for loop. I just have an Rounds++ variable Maybe I can send you my code again?
Array
ArrayOP12mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ @JP https://paste.mod.gg/dpmedmelnbfo/0 Can you guys check out where I messed up ?
BlazeBin - dpmedmelnbfo
A tool for sharing your source code with the world!
Array
ArrayOP12mo ago
I put it outside and it still didn't function sadly
Angius
Angius12mo ago
You have a loop though Place the rounds variable nearest to the loop whose iterations you want to count No need to place it this far out Unless you want to count total rounds of all the games the player played, then sure
Array
ArrayOP12mo ago
I'm a bit confused though, is it not in the do while loop ? the Rounds++: counter Like it is within the do while loop is it supposed to be in the if else statements you mean?
Angius
Angius12mo ago
You have the rounds variable declared in front of your big loop
No description
Angius
Angius12mo ago
Is it supposed to be there? Instead of in front of the small loop? So that each game can count rounds separately? Or do you actually want to count all rounds of all the games played? If so, carry on But then don't reset the rounds count to zero with every inner loop iteration
Array
ArrayOP12mo ago
I want to count how many rounds it took in total til they won or lost, yea Ohhh I get what you're saying my bad I want it to be seperate Wondering, why does it matter where I declare the variable?
Angius
Angius12mo ago
Here's another thing
No description
Angius
Angius12mo ago
You increment the Rounds at the end of the loop But at the start you reset it to 0 again It can never increase Because you reset it each time
Array
ArrayOP12mo ago
How should I fix this?
Angius
Angius12mo ago
Move the variable outside of the loop and don't reset it
Array
ArrayOP12mo ago
wdym by dont reset it ?
Angius
Angius12mo ago
You're doing
var rounds = 0;
while (run)
{
rounds = 0;
// code code code code
rounds++;
}
var rounds = 0;
while (run)
{
rounds = 0;
// code code code code
rounds++;
}
Can you see how with every loop iteration the value of rounds will be reset to zero?
Array
ArrayOP12mo ago
ya because when it ends it resets to 0
Angius
Angius12mo ago
Do this:
var rounds = 0;
while (run)
{
// code code code code
rounds++;
}
var rounds = 0;
while (run)
{
// code code code code
rounds++;
}
Array
ArrayOP12mo ago
So the rounds++; counter is supposed to be within my if else statements, right?
Angius
Angius12mo ago
Within the loop You're counting the iterations of the loop Your increment is where it should be But you also reset the rounds value with each iteration Don't
Array
ArrayOP12mo ago
test ```cs //if statements to check if user won, lost, or needs to loop again to play if (Sum == 7) { Console.WriteLine("CONGRATS!!!! THESE TWO ROLLS SUM TO 7, YOU WON!"); RunGame = false; //ask to play again Console.WriteLine(""); Console.WriteLine("Enter a 1 to Play Again!"); PlayAgain = Console.ReadLine(); Rounds = 0; } else if (Sum == 11) { Console.WriteLine("CONGRATS!!! THESE TWO ROLLS SUM TO 11, YOU WON"); RunGame = false; //ask to play again Console.WriteLine(""); Console.WriteLine("Enter a 1 to Play Again!"); PlayAgain = Console.ReadLine(); Rounds++; } else if (RolledDiceOne == RolledDiceTwo) { Console.WriteLine("YOU ROLLED TWO OF THE SAME NUMBER, A DOUBLE! YOU LOSE."); RunGame = false; //ask to play again Console.WriteLine(""); Console.WriteLine("Enter a 1 to Play Again!"); PlayAgain = Console.ReadLine(); Rounds++; } else { Console.WriteLine("Well.. you neither won or lost! Roll again to see if you win or lose next time."); Rounds++; } oops @ZZZZZZZZZZZZZZZZZZZZZZZZZ is this how it is supposed to be?
Angius
Angius12mo ago
You forgot the closing backticks
Array
ArrayOP12mo ago
thanks
Angius
Angius12mo ago
Is this supposed to reset the counter when the player gets 7?
Array
ArrayOP12mo ago
do
{

int RolledDiceOne = RandGenerator.Next(1, 7);
int RolledDiceTwo = RandGenerator.Next(1, 7);
int Sum = RolledDiceOne + RolledDiceTwo;
Rounds = 0;


Console.WriteLine("Enter any key to ROLL your 1st die:");
Console.ReadKey(true);
Console.WriteLine("Awesome! For your first roll, you rolled: " + RolledDiceOne + "!");
Console.WriteLine("");

Console.WriteLine("Let's see if you win or lose with your second roll.");
Console.WriteLine("Enter any key to ROLL your 2nd die:");
Console.ReadKey(true);
Console.WriteLine("This time on your second roll, you rolled: " + RolledDiceTwo + "....");
Console.WriteLine("");



if (Sum == 7)
{
Console.WriteLine("CONGRATS!!!! THESE TWO ROLLS SUM TO 7, YOU WON!");
RunGame = false;
//ask to play again
Console.WriteLine("");
Console.WriteLine("Enter a 1 to Play Again!");
PlayAgain = Console.ReadLine();
Rounds++;

}
else if (Sum == 11)
{
Console.WriteLine("CONGRATS!!! THESE TWO ROLLS SUM TO 11, YOU WON");
RunGame = false;
//ask to play again
Console.WriteLine("");
Console.WriteLine("Enter a 1 to Play Again!");
PlayAgain = Console.ReadLine();
Rounds++;

}
else if (RolledDiceOne == RolledDiceTwo)
{
Console.WriteLine("YOU ROLLED TWO OF THE SAME NUMBER, A DOUBLE! YOU LOSE.");
RunGame = false;
//ask to play again
Console.WriteLine("");
Console.WriteLine("Enter a 1 to Play Again!");
PlayAgain = Console.ReadLine();
Rounds++;
}
else
{
Console.WriteLine("Well.. you neither won or lost! Roll again to see if you win or lose next time.");
Rounds++;
}

//count each round
Rounds++;
Console.WriteLine("It took you {0} Round(s)", Rounds);


} while (RunGame = RunGame || PlayAgain == "1");
do
{

int RolledDiceOne = RandGenerator.Next(1, 7);
int RolledDiceTwo = RandGenerator.Next(1, 7);
int Sum = RolledDiceOne + RolledDiceTwo;
Rounds = 0;


Console.WriteLine("Enter any key to ROLL your 1st die:");
Console.ReadKey(true);
Console.WriteLine("Awesome! For your first roll, you rolled: " + RolledDiceOne + "!");
Console.WriteLine("");

Console.WriteLine("Let's see if you win or lose with your second roll.");
Console.WriteLine("Enter any key to ROLL your 2nd die:");
Console.ReadKey(true);
Console.WriteLine("This time on your second roll, you rolled: " + RolledDiceTwo + "....");
Console.WriteLine("");



if (Sum == 7)
{
Console.WriteLine("CONGRATS!!!! THESE TWO ROLLS SUM TO 7, YOU WON!");
RunGame = false;
//ask to play again
Console.WriteLine("");
Console.WriteLine("Enter a 1 to Play Again!");
PlayAgain = Console.ReadLine();
Rounds++;

}
else if (Sum == 11)
{
Console.WriteLine("CONGRATS!!! THESE TWO ROLLS SUM TO 11, YOU WON");
RunGame = false;
//ask to play again
Console.WriteLine("");
Console.WriteLine("Enter a 1 to Play Again!");
PlayAgain = Console.ReadLine();
Rounds++;

}
else if (RolledDiceOne == RolledDiceTwo)
{
Console.WriteLine("YOU ROLLED TWO OF THE SAME NUMBER, A DOUBLE! YOU LOSE.");
RunGame = false;
//ask to play again
Console.WriteLine("");
Console.WriteLine("Enter a 1 to Play Again!");
PlayAgain = Console.ReadLine();
Rounds++;
}
else
{
Console.WriteLine("Well.. you neither won or lost! Roll again to see if you win or lose next time.");
Rounds++;
}

//count each round
Rounds++;
Console.WriteLine("It took you {0} Round(s)", Rounds);


} while (RunGame = RunGame || PlayAgain == "1");
@ZZZZZZZZZZZZZZZZZZZZZZZZZ I fixed the 7 thing that was an error well discord still kinda messed it up
Angius
Angius12mo ago
You still reset the Rounds back to zero at the start of the loop
Array
ArrayOP12mo ago
but i want to increment after every 2 rolls What should I set it to?
Angius
Angius12mo ago
? It should not be set at all
Array
ArrayOP12mo ago
oh
Angius
Angius12mo ago
Declare the variable with the value of 0 BEFORE the loop Increment the variable INSIDE the loop Do not change the variable IN ANY OTHER WAY inside of the loop
rounds = 0
loop {
rounds++
}
rounds = 0
loop {
rounds++
}
that's all
Array
ArrayOP12mo ago
Right so I set it to int Rounds = 0; before the loop Okay I'll try running it @ZZZZZZZZZZZZZZZZZZZZZZZZZ thanks for your paitence with me
Array
ArrayOP12mo ago
I noticed it says 2 rounds, which is nearly right, but I'd want it to say 1 round since the user won immeditaely
No description
Array
ArrayOP12mo ago
I should also probably remove the counter on losses, only keep it for wins
Want results from more Discord servers?
Add your server