Beginner at C sharp, Having problems with Exponentiation

So it states do Math.Pow() but what do i do after that
120 Replies
Angius
Angius3y ago
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?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I'm confused
Angius
Angius3y ago
The same way + needs a left and a right value to sum, Math.Pow() needs two parameters
Kaoruko Waguri
Kaoruko WaguriOP3y ago
like
Angius
Angius3y ago
It even says so
Kaoruko Waguri
Kaoruko WaguriOP3y ago
double.Parse??
Kouhai
Kouhai3y ago
I think they are having trouble understanding how they should get the values from the input boxes?
Angius
Angius3y ago
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 example
MODiX
MODiX3y ago
Angius#1586
REPL Result: Success
Math.Pow(10, 2)
Math.Pow(10, 2)
Result: double
100
100
Compile: 302.167ms | Execution: 18.188ms | React with ❌ to remove this embed.
Kaoruko Waguri
Kaoruko WaguriOP3y ago
does this work? label4.Text = Math.Pow (double.Parse(One.Text) (double.Parse(Second.Text)).ToString();
Angius
Angius3y ago
Well, does it?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
no
Angius
Angius3y ago
And what's the issue?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
(double.Parse(One.Text) is underlined
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
You have one too many (s Count your opening parentheses in this line, and count your closing parentheses
Kaoruko Waguri
Kaoruko WaguriOP3y ago
og
Angius
Angius3y ago
I'd use variables to make it cleaner
var a = double.Parse(One.Text);
var b = double.Parse(Two.Text);
var result = Math.Pow(a, b);
label4.Text = result.ToString();
var a = double.Parse(One.Text);
var b = double.Parse(Two.Text);
var result = Math.Pow(a, b);
label4.Text = result.ToString();
Splitting up your code does wonders to clarity
Kaoruko Waguri
Kaoruko WaguriOP3y ago
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
Angius
Angius3y ago
Your teacher didn't tell you about variables..? Or about var?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
nope I tried using "IF" and he got mad
Angius
Angius3y ago
Why the fuck is he teaching you Winforms before variables
Kaoruko Waguri
Kaoruko WaguriOP3y ago
idk
Angius
Angius3y ago
Some teachers out there are a waste of oxygen, I swear
Kaoruko Waguri
Kaoruko WaguriOP3y ago
but I'll try to learn Var and variables
Angius
Angius3y ago
Well, do it their way, I guess
Kaoruko Waguri
Kaoruko WaguriOP3y ago
outside of school
Angius
Angius3y ago
$helloworld is a great resource for learning the basics
Angius
Angius3y ago
Such as variables
Kaoruko Waguri
Kaoruko WaguriOP3y ago
thanks 🙂 I still don't understand what you mean
Angius
Angius3y ago
Angius
Angius3y ago
Every opening parentheses ( has to be closed with ) If the numbers of ( and ) in a statement don't match, that means something's wrong
Kaoruko Waguri
Kaoruko WaguriOP3y ago
ooh So I did this Math.Pow (double.Parse)(One.Text) (double.Parse(Second.Text)).ToString(); but the Pow is underlined for some reason
Angius
Angius3y ago
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 sense
Kaoruko Waguri
Kaoruko WaguriOP3y ago
just adding more )) wont work I'm gonna take a break, I still don't understand
Angius
Angius3y ago
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
MODiX
MODiX3y ago
Angius#1586
var a = double.Parse(One.Text);
var b = double.Parse(Two.Text);
var result = Math.Pow(a, b);
label4.Text = result.ToString();
var a = double.Parse(One.Text);
var b = double.Parse(Two.Text);
var result = Math.Pow(a, b);
label4.Text = result.ToString();
React with ❌ to remove this embed.
Angius
Angius3y ago
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 many
Henkypenky
Henkypenky3y ago
hi, 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
Kaoruko Waguri
Kaoruko WaguriOP3y ago
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);
Angius
Angius3y ago
Where's the closing parenthesis of Math.Pow()?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
once I put a parentheses down the Pow gets underlined and semicolon
Angius
Angius3y ago
Where are you putting it?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
radiobutton/Exponentiation
Angius
Angius3y ago
The parenthesis
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Math.Pow() (Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text);
Angius
Angius3y ago
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 inferior
Kaoruko Waguri
Kaoruko WaguriOP3y ago
I asked my teacher and he said to try ToDouble not really said but he just gave me the full code
Angius
Angius3y ago
Ah, almost forgot your teacher is an idiot That still leaves us the parentheses
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Convert.ToDouble(One.Text)
Angius
Angius3y ago
So you're calling it with MethodName(Parameters) right?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah
Angius
Angius3y ago
Why Math.Pow() (Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text) then? MethodName()(Parameters This is what you did here
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
You're missing the closing parenthesis MathPow( <— cool, open parenthesis Where is it closing?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
the ToString?
Angius
Angius3y ago
what
Kaoruko Waguri
Kaoruko WaguriOP3y ago
.ToString()
Angius
Angius3y ago
There's no .ToString() there Give me a second
Kaoruko Waguri
Kaoruko WaguriOP3y ago
okay
Angius
Angius3y ago
I see I just need to make a drawing
Angius
Angius3y ago
Angius
Angius3y ago
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
Kaoruko Waguri
Kaoruko WaguriOP3y ago
ooooh had one more parenthesis I've been doing it at )) Math.Pow(Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text)); like that right
Angius
Angius3y ago
Yes, bravo
Kaoruko Waguri
Kaoruko WaguriOP3y ago
quick question some code can have double closing parenthesis right?
Angius
Angius3y ago
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
Foo(
Bar(
Baz(
61
)
)
)
Foo(
Bar(
Baz(
61
)
)
)
Pairs
Kaoruko Waguri
Kaoruko WaguriOP3y ago
oh something happend
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
One of your inputs wasn't a valid double
Kaoruko Waguri
Kaoruko WaguriOP3y ago
quick question I can still change ToDouble to Double.Parse right?
Angius
Angius3y ago
?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
nvm what do you mean?
Angius
Angius3y ago
"potato" is not a valid double 73134.974 is
Anchy
Anchy3y ago
my potatoes double all the time it might be a good idea to use TryParse here
Angius
Angius3y ago
Their teacher is a waste of oxygen and doesn't let them even use variables yet, apparently And forces the use of Convert as well
Anchy
Anchy3y ago
i can no longer be of further assistance
MODiX
MODiX3y ago
Angius#1586
REPL Result: Failure
Convert.ToDouble("potato")
Convert.ToDouble("potato")
Exception: FormatException
- Input string was not in a correct format.
- Input string was not in a correct format.
Compile: 536.909ms | Execution: 26.372ms | React with ❌ to remove this embed.
MODiX
MODiX3y ago
Angius#1586
REPL Result: Success
Convert.ToDouble("2335")
Convert.ToDouble("2335")
Result: double
2335
2335
Compile: 625.057ms | Execution: 28.508ms | React with ❌ to remove this embed.
MODiX
MODiX3y ago
Angius#1586
REPL Result: Success
Convert.ToDouble("6234.654")
Convert.ToDouble("6234.654")
Result: double
6234.654
6234.654
Compile: 609.311ms | Execution: 22.562ms | React with ❌ to remove this embed.
Angius
Angius3y ago
As you can see, the value entered has to be a valid whole or decimal number
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
Well, huh, that should work
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Wait do I put the code under the label?? not under the radiobutton
Angius
Angius3y ago
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
Angius
Angius3y ago
What I see in that screenshot, is that both texts were empty
Kaoruko Waguri
Kaoruko WaguriOP3y ago
yeah I didn't put anything yet
Angius
Angius3y ago
Well, an empty string is not a valid double So no wonder it threw an error
Kaoruko Waguri
Kaoruko WaguriOP3y ago
55^55 = 5.2474453e+95 that right? right
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
Try some smaller numbers first
Anchy
Anchy3y ago
yes
Anchy
Anchy3y ago
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
How are you displaying the answer? label1.Text = Math.Pow( ... ).ToString(); ?
Kaoruko Waguri
Kaoruko WaguriOP3y ago
wait I had to put a label
Angius
Angius3y ago
Or wherever else you want to display the result
Kaoruko Waguri
Kaoruko WaguriOP3y ago
label4.Text = Math.Pow(Convert.ToDouble(One.Text), Convert.ToDouble(Second.Text));
Angius
Angius3y ago
But you want to display it... somewhere, right? Something like that, yeah Might need the .ToString()
Kaoruko Waguri
Kaoruko WaguriOP3y ago
for addition this code works label4.Text = (Convert.ToDouble(One.Text) + Convert.ToDouble(Second.Text)).ToString();
Kaoruko Waguri
Kaoruko WaguriOP3y ago
Angius
Angius3y ago
Add that .ToString() then
Kaoruko Waguri
Kaoruko WaguriOP3y ago
it works
Angius
Angius3y ago
Nice
Kaoruko Waguri
Kaoruko WaguriOP3y ago
@Angius thanks for not giving up on me sorry for teaching a dumbass like me
Angius
Angius3y ago
That's what we're for in this server, to teach people 👌
Kaoruko Waguri
Kaoruko WaguriOP3y ago
thanks soo much now to do birthdays
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Angius
Angius3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
i love cat(mull-rom splines)
oh wow this might be the first hijacking of a thread ever
Kaoruko Waguri
Kaoruko WaguriOP3y ago
@Angius do I need to make new thread? for a different question or can I just use this one?
Angius
Angius3y ago
Either's fine
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Angius
Angius3y ago
You'll have better chances getting an answer if you start your own thread, instead of hijacking someone else's
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3y ago
Tsukasa Tsukuyomi#2903
So it states do Math.Pow() but what do i do after that
From Tsukasa Tsukuyomi#2903
React with ❌ to remove this embed.
Angius
Angius3y ago
Here's the message that started this thread My eyes might be playing tricks on me, but it doesn't seem like your name
Want results from more Discord servers?
Add your server