C
C#14mo ago
Yuvi

❔ Code Block not being executed.

Hi, the code block after is just not being executed, I used Console.WriteLIne to confirm my lines 49 and 50 were being printed correctly.....I have just started. This was in a tutorial, I rechecked the code 10 times and still can't figure out the problem. The solution just shows up as what I uploaded in the second picture, I can type more stuff, idk how and why but I can. Either way, that's not what I wanted to happen. What I wanted was for it to just continue on with the code block and print the result with the final Console.Readline Sorry for asking such A B C questions of programming...I am still learning ABC...but I really dont know, cant progress further in lesson like this >:(
No description
No description
22 Replies
Pobiega
Pobiega14mo ago
can you show your code and not as a screenshot? $code
MODiX
MODiX14mo ago
Posting Code Snippets To post a code snippet type the following: ```cs // code here ``` Notes: - Get an example by typing $codegif in the chat. - Change the language by replacing cs with the language of your choice (for example sql or cpp). - If your code is too long, you can post it to https://paste.mod.gg/ and share the link.
Pobiega
Pobiega14mo ago
you also mention line numbers in your post, but omitted them in the screenshot :p
Yuvi
YuviOP14mo ago
Do I just copy paste the entire code? Oops sorry. $cidegif
Pobiega
Pobiega14mo ago
sure. if its too long, use the URL the bot posted
Yuvi
YuviOP14mo ago
BlazeBin - bitticmtbvqx
A tool for sharing your source code with the world!
Yuvi
YuviOP14mo ago
Does this work? First time interacting with a coding community, not aware of basic things yet lol.
Pobiega
Pobiega14mo ago
yep that works
Saber
Saber14mo ago
while (counter > result) does this logically make sense for what you are trying to do. Is 1 > 3 true or false
Yuvi
YuviOP14mo ago
true
Pobiega
Pobiega14mo ago
while (counter > result)
{
Console.WriteLine(counter);
Console.Write("-");
Console.WriteLine(counter++);
}
while (counter > result)
{
Console.WriteLine(counter);
Console.Write("-");
Console.WriteLine(counter++);
}
Yuvi
YuviOP14mo ago
wait
Saber
Saber14mo ago
1 > 3? til
Yuvi
YuviOP14mo ago
oh It was supposed to be the other way around wasn't it Because 1 isnt a bigger value than 3
g33b1c
g33b1c14mo ago
correct
Yuvi
YuviOP14mo ago
Thank you very much, I uh, well brainfarted. I didnt expect such instant blushowo
g33b1c
g33b1c14mo ago
You should also prevent entering a number smaller than 0, otherwise your While loop will continue to run indefinitely.
Yuvi
YuviOP14mo ago
Ohhh, I'll try to see if I can do something like that. Thanks for the advice.
g33b1c
g33b1c14mo ago
If you change your While clause to <= you can ignore the check for less than 0. But you should check before the int.parse if the input is a number.
Yuvi
YuviOP14mo ago
I was thinking if there was a way to make the user only be able to input integers, I searched, but everything was going above my head so I thought I'll think about that another time.
g33b1c
g33b1c14mo ago
you could use somthing like that The tryparse function tries to convert the value to an int, if this doesn't work the "out" parameter will be 0
private static void PrintNumbers()
{
int counter = 1;
int result;
Console.Clear();
Console.WriteLine("Print numbers!");
Console.Write("Type a number: ");
int.TryParse(Console.ReadLine(),out result);
if (result == 0)
{
Console.WriteLine("The entered value is not a number");
}
else
{
while (counter <= result)
{
Console.Write(counter);
Console.Write("-");
counter++;
}
}
Console.ReadLine();
}
private static void PrintNumbers()
{
int counter = 1;
int result;
Console.Clear();
Console.WriteLine("Print numbers!");
Console.Write("Type a number: ");
int.TryParse(Console.ReadLine(),out result);
if (result == 0)
{
Console.WriteLine("The entered value is not a number");
}
else
{
while (counter <= result)
{
Console.Write(counter);
Console.Write("-");
counter++;
}
}
Console.ReadLine();
}
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server