Beginner at C sharp, Having problems with Exponentiation
So it states do Math.Pow() but what do i do after that
120 Replies
Well,
Math.Pow()
takes two parameters — the base and the exponent — and returns a result
Just calling Math.Pow()
is about equal to saying "to the power of"
What to the power of what?
What to do with the result?I'm confused
The same way
+
needs a left and a right value to sum, Math.Pow()
needs two parameterslike
It even says so
double.Parse??
I think they are having trouble understanding how they should get the values from the input boxes?
Yes, that's a method as well
Methods, in general, take parameters
Not all of them do
But
Math.Pow()
and double.Parse()
do, for exampleAngius#1586
REPL Result: Success
Result: double
Compile: 302.167ms | Execution: 18.188ms | React with ❌ to remove this embed.
does this work? label4.Text = Math.Pow (double.Parse(One.Text) (double.Parse(Second.Text)).ToString();
Well, does it?
no
And what's the issue?
(double.Parse(One.Text) is underlined
You have one too many
(
s
Count your opening parentheses in this line, and count your closing parenthesesog
I'd use variables to make it cleaner
Splitting up your code does wonders to clarity
I can split it up
just saying my class hasn't gone that far yet and if I do try it my teacher would get mad at me. He wan't me to try to do what he taught us
Your teacher didn't tell you about variables..?
Or about
var
?nope
I tried using "IF" and he got mad
Why the fuck is he teaching you Winforms before variables
idk
Some teachers out there are a waste of oxygen, I swear
but I'll try to learn Var and variables
Well, do it their way, I guess
outside of school
$helloworld is a great resource for learning the basics
Written interactive course https://docs.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
Such as variables
thanks 🙂
I still don't understand what you mean
Every opening parentheses
(
has to be closed with )
If the numbers of (
and )
in a statement don't match, that means something's wrongooh
So I did this Math.Pow (double.Parse)(One.Text) (double.Parse(Second.Text)).ToString(); but the Pow is underlined for some reason
Because your code still makes no sense
You had one
(
too many
Not one )
too few
(
opens the list of parameters in a method call, )
closes it
(double.Parse)(One.Text)
makes no sensejust adding more )) wont work
I'm gonna take a break, I still don't understand
Just randomly slapping parentheses around won't help
Also, just noticed, you're missing a comma there as well
When a method has multiple parameters, they have to be separated by a comma
Angius#1586
Quoted by
<@!85903769203642368> from #Beginner at C sharp, Having problems with Exponentiation (click here)
React with ❌ to remove this embed.
Like here
a, b
A method call uses one pair of parentheses
You should have one pair for double.Parse(One.Text)
, one for double.Parse(Two.Text)
, and one for Math.Pow( ... )
You have one (
too manyhi, pardon the intrusion, my suggestion would be to start with the basics, just a console app, seems like you need to understand the basics first and putting forms on top of everything is not gonna help much
my 2 cents
I appreciate the advice, but if I start at the beginning and take lessons online, I worry that I might become confused between my irl class. I'm not sure tho
I think this works Math.Pow(Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text);
Where's the closing parenthesis of
Math.Pow()
?once I put a parentheses down the Pow gets underlined and semicolon
Where are you putting it?
radiobutton/Exponentiation
The parenthesis
Math.Pow() (Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text);
Well that's not where it goes
Do you call
Convert.ToDouble()One.Text
or Convert.ToDouble(One.Text)
?
Also... why did you go from double.Parse()
to Convert.ToDouble()
..? The latter is strictly inferiorI asked my teacher and he said to try ToDouble
not really said but he just gave me the full code
Ah, almost forgot your teacher is an idiot
That still leaves us the parentheses
Convert.ToDouble(One.Text)
So you're calling it with
MethodName(Parameters)
right?yeah
Why
Math.Pow() (Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text)
then?
MethodName()(Parameters
This is what you did hereYou're missing the closing parenthesis
MathPow(
<— cool, open parenthesis
Where is it closing?the ToString?
what
.ToString()
There's no
.ToString()
there
Give me a secondokay
I see I just need to make a drawing
Orange method has an open and closed parenthesis
So does the green method
The blue method has an open one... but not a closing one
ooooh
had one more parenthesis
I've been doing it at ))
Math.Pow(Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text));
like that right
Yes, bravo
quick question some code can have double closing parenthesis right?
Uh
It's not some weird
))
operator
There's no such thing as "double closing parenthesis"
One of them closes Convert.ToDouble()
The other closes Math.Pow()
Foo(Bar(Baz(61)))
doesn't have some magic triple-parenthesis
It's just
Pairsoh
something happend
One of your inputs wasn't a valid double
quick question I can still change ToDouble to Double.Parse right?
?
nvm
what do you mean?
"potato"
is not a valid double
73134.974
ismy potatoes double all the time
it might be a good idea to use TryParse here
Their teacher is a waste of oxygen and doesn't let them even use variables yet, apparently
And forces the use of
Convert
as welli can no longer be of further assistance
Angius#1586
REPL Result: Failure
Exception: FormatException
Compile: 536.909ms | Execution: 26.372ms | React with ❌ to remove this embed.
Angius#1586
REPL Result: Success
Result: double
Compile: 625.057ms | Execution: 28.508ms | React with ❌ to remove this embed.
Angius#1586
REPL Result: Success
Result: double
Compile: 609.311ms | Execution: 22.562ms | React with ❌ to remove this embed.
As you can see, the value entered has to be a valid whole or decimal number
Well, huh, that should work
Wait do I put the code under the label??
not under the radiobutton
You put the code where you want to execute it
If you want to execute it on radio button click, you put it in the method that fires on radio button click
What I see in that screenshot, is that both texts were empty
yeah I didn't put anything yet
Well, an empty string is not a valid double
So no wonder it threw an error
55^55 = 5.2474453e+95 that right? right
Try some smaller numbers first
yes
How are you displaying the answer?
label1.Text = Math.Pow( ... ).ToString();
?wait I had to put a label
Or wherever else you want to display the result
label4.Text = Math.Pow(Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text));
But you want to display it... somewhere, right?
Something like that, yeah
Might need the
.ToString()
for addition this code works
label4.Text = (Convert.ToDouble(One.Text) + Convert.ToDouble(Second.Text)).ToString();
Add that
.ToString()
thenit works
Nice
@Angius thanks for not giving up on me sorry for teaching a dumbass like me
That's what we're for in this server, to teach people 👌
thanks soo much
now to do birthdays
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Perhaps in your own thread, or in #help-0 where you already crossposted.
Don't hijack other people's threads looking for help
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
oh wow
this might be the first hijacking of a thread ever
@Angius do I need to make new thread? for a different question or can I just use this one?
Either's fine
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
You'll have better chances getting an answer if you start your own thread, instead of hijacking someone else's
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Tsukasa Tsukuyomi#2903
So it states do Math.Pow() but what do i do after that
Quoted by
<@!85903769203642368> from #Beginner at C sharp, Having problems with Exponentiation (click here)
React with ❌ to remove this embed.
Here's the message that started this thread
My eyes might be playing tricks on me, but it doesn't seem like your name