151 Replies
here we are. Thank you for helping out.
So I don't know why but the Executionflow confuses me a wee bit, so I thought I would replicate your scenario to see where I am fekking up.
so lemme explain it quickly
in short
`
This is what I copied
so i have a school assignment where i need to make 12 different calculators that i know how to make and now is the issue where i forgot how to return back to the start of the code when it breaks out of that specific loop when the user types in a char instead of a int
It's true that this Gives hickups.
The
ReadLine-Method takes String by default, and your TryParse Operation Is correct.
and the first if statement says that if it cannot parse it from a string to a int that is bigger than 1 and less the 13 it will spit out a line where it says "wrong information given please pick a calculation between the numbers 1-12
point of the tryparse is that i ensure the user dont input a char instead of a int by accident
This is also good.
It's just doing the same verification from a different angle.
I'm going to run your code line-by-Line with the debugger, to see how this Execution context does it's work.
good?
mhm
just pointing it out again that everything works perfectly fine but on the last part i want it to return to the start of the code again but i dont know how to tell it
im new to programming
hehe
this is the first year of programming in my high school at sweden
I am myself a Self employed Graphic designer Rolling into C# from Python, So much of what we're doing now I am supposed to be capable of handling, but I too am learning this.
I'm currently making a mess of brackets, sorry.
haha np man take youre time
Have you learned about methods yet?
A great way to solve this would be to break up your really big
Main
method in smaller methodsnope dont even know what that is
ok... what about
switch
?ah yeah know about dat
Can you see a good usecase for it here?
this is what we are following rn from our teacher
we on bool rn
W3 is a good source for rookie-material.
But in all fairness, they are a bit hesitant on updating on new changes.
huh? but bool is above both switch, if/else, while...
what the helvete is your lärare doing
bro its a spanish teacher that is teaching us
he can barely teach other people in a proper way
like i have to go out of my way and go teach my self
cuz how bad this only programming teacher we have at our high school
🙂
Unfortunately this is not rare
"Don't let school get in the way of your education" is a saying for a reason
im at school for a reason bro i want to be tought/teached 🤣
lol, I get no errors from inside the code, but somehow the Main method is not being recognised as a valid entry point.
Current code looks like this:
did I forget somehting?
I'm confused. Who is helping who here? 😄
me
I am ( trying to help him out)
but I am not as speedy as I want to be.
um
how do i do the grey thingis like your text
$codegif
you skipped a step
that is ?
cs
after the first backticksits tripple backtick,
cs
, enter
paste enter
tripple backtick
enterdisco!
mhm but now how do i make it return to the top of the code
after a string has been inputed
let me clean that up for you
tada
thx now HOW cuz i need to hand this is today
There is quite a bit wrong with this code as is to be honest
that is
pls tell me
to manipulate controlflow of your code you could employ jumpstatements.
But they are generally frowned upon.
Well, look at where you read the input and where you parse it
those should reasonably be next to eachother, and definately not on either side of a
while(true)
point of that is so the user does not enter a char
instead of a int
I understand that
But how many times does this code ask the user to write a value?
only once
only once.
so if you gave it... say "cheese"
oooooooooooooooooooooooooooooooooooooooooooh
now i get it
it will actually end in a forever loop that you cant escape
i put the input part in a while loop to
yes
HAHHAHA thanks bro youre the best
I LOVE YOU
he is
cheers mate.
i was literally thinking for an hour today in the class and i couldnt figure out
what the next step to do
you tell us
I can immediately identify one thing thats not quite right thou
that is ?
In what scenario can the execution reach the red marked line
after it tried the parse
all the needed information is in the screenshot.
so i have to have the input check first then it tells me that the info is wrong or not
right ?
Im not sure what you are asking tbh
but its not relevant to my question
nvm yeah it is
Look at the piece of code I screenshotted and where the red line is
im just mind fucking u
hehe
assume we reach the while loop
when can we enter the if?
during what scenario/condition?
when the number is smaller then 12
no no
bigger
right. But when can we enter the while loop?
when the input is smaller then 12
so 11
well, between 1 and 12
so a value that is guaranteed to be between 1 and 12... can't really be above 12, can it?
bro bro i forgot to tell you
the point of that is to tell the user that you can only pick thrue these numbers
I understand
then it enters the if and tells the user
That is what kept throwing me off.
I thought i was losing the ability to read lol
its the swedish part
haha
Uncle. Look at my bio.
vänta vah
hahaha
See anything that stands out? 😛
HAHHAHAHAHAHHAHA
so i take that back what i said
Glad to have you on board tho.
Now, back to the numbers
yes
Can you name a number that is between 1 and 12, but also greater than 12
5 and 13 ?
no a single number
hm
dafuq
indeed
its a trick question, its obviously impossible
so i have not told it what number i want it to be on the else part right ?
What im trying to get to is...
?
bro chill I need to draw
ok mb
the red block is only ever accessed by a number that is 1 to 12
the green block is only ever accessed by a number that is both between 1-12, but also equal too or greater than 12
thats a really convoluted way to say
12
you could easily remove the green block and just reduce the top limit by 1 in the while
however
that while is itself weird
its a while with a constant condition, as you never modify userMainInput
inside the loop
so its another forever-loop 🙂well i have before
the loop
i think
nvm
sure before the loop
but a loop with a constant condition is the same as
while(true)
(assuming your condition evaluates to true)what the hell thats the wrong code
kompis det är fel
its your code.
or whatever was pasted here
I did not write this 😛
wait heres the original
here is the code I took
so basically youre trying to tell me the 2 while loops is useless
only need 1 right ?
remove the true on and just add it to the if statement
no
fan
if only 1 to 11 are the valid numbers, why does your condition allow 12?
It's the peculiar conditioning for those 2 loops that make for unnessecery nesting, - if those conditions never will be met then the code is not following its function
i fixed that to 11
why is the message about invalid numbers INSIDE the body that has been checked so the number is valid?
ok, updated
now the value is 1-11, so it can never be 12 or greater
so we can remove the green block
exactly
yes
it now looks like this
well bro the point of that green block i just remembered that i wanted to tell the user
that
that loop will get broken immediately, meaning this is just a weird way to write
if
😄
I know
you dont need to explain
Im saying you dont need that block, because you already have that blockso if its not 1-11 it just countinues on the next part of the code ?
yes
oh
so you see how thats literally just an
if
right?yeah yeah
cool
ill just add other part where to check if its a string or a int
btw, I want to change something fairly big.. do you know what
!true
is?not true ?
exactly
teach me
The way you are structuring your code right now with increasing levels of nesting is... not great
we can inverse most of those nestings
realised that
for example, the loop that makes sure you entered a valid value? well if we inverse that...
how will it look like
its now a lot shorter
we should fix a few more things thou
we should keep asking them for a number until its not just a number, but a number between 1 and 11
so why not do that in the same loop?
Can you figure out a way to do that?
so my code works fine just the issue is that i have nested the shit that makes the loop for the number checking fuck up if the value is between 1-11 right ?
alltså kåden startar ej om och säger att du har valt fel nummer istället så stänger den ba av ellerhur ?
?
English only on the server please.
I honestly kinda dont know what "works" looks like, Im just fixing issues as I see them
bad design is an issue in my eyes 🙂
mhm you did
thx for the help man
lemme fix it and ill show u how it looks
Also Thanks for letting me tag along.
any time 😄
list of help threads I'm active in
fixed it yay
works perfectly as i wanted
.. I somehow doubt that
whaaat why you dont have faith in the newcomer
it actually works
try it
I dont need to. I can read it
ah ok
wait, oooh.
You only wanted to validate numbers=
that was the entire programs purpose?
what now
HAHHAA YESSSS
wtf
then i can continue
with the rest
also, the
if() { break; }
makes me feel very uneasy 😄
I know I wrote it, but it feels so badlol, I thought it had to represent a calculation.
🙂
it does
the namespace is literally "calculator"
now i can just paste everything in
Cheers tho. I'm off for homework.
the calcutlation of second degree question, quadratic calculation
this is the main is i had now everything is gonna run perfectly fine
yo
@Pobiega you still there ?
Every now and then
you still there ?
?
just ask your question