C
C#3y ago
maroonlol

Hi, I'm having a error in my code in Visual studio and I'm writing with C

Thank you for your time
23 Replies
Ezlanding
Ezlanding3y ago
What does the error say?
maroonlol
maroonlolOP3y ago
maroonlol
maroonlolOP3y ago
this is what it says
Ezlanding
Ezlanding3y ago
Cast it to a double/decimal So (double)number The error is because you passed in an integer, a number that could be either a double or a decimal, meaning c# is unsure which overload to call. Casing it to double/decimal unambiguates the call
maroonlol
maroonlolOP3y ago
That fixes the error, however I would like it so that the user can choose how many decimal places he would like it too. but the program now ignores that and just displays the number with a long decimal unspecified to the input Thank you for also explaining for me I was searching it up but it wasn't explained as simple and clear as you did Would you know what is wrong with this?
Ezlanding
Ezlanding3y ago
Does shift2 not do that? ^ @Abdul Raheem Nazir
maroonlol
maroonlolOP3y ago
Unfortunately no and I'm not sure why not
Ezlanding
Ezlanding3y ago
see here, this outputs 1.2 var i = Math.Round(1.239482823381, 1); Console.WriteLine(i); What does it output for you?
maroonlol
maroonlolOP3y ago
maroonlol
maroonlolOP3y ago
it outputs the long decimal when I wanted only to one decimal place
Ezlanding
Ezlanding3y ago
@Abdul Raheem Nazir you round number, but you print root
maroonlol
maroonlolOP3y ago
I just realised I need to make a new variable for the the new rounded number😅 Thank you so much, I think that deals with my main issue Have a blessed day
Ezlanding
Ezlanding3y ago
Thanks you too! 👍
maroonlol
maroonlolOP3y ago
maroonlol
maroonlolOP3y ago
O'm sorry im back again😅 It is printing the value entered now and not calculating the square toot
Ezlanding
Ezlanding3y ago
shift3 = Math.Round… and take out line 134 You are setting shift3 to Console.Readline, which is what you user enters So when you print shift3 you are printing what the user entered
maroonlol
maroonlolOP3y ago
I think this is what you meant however I have tried that but then i get another error
maroonlol
maroonlolOP3y ago
maroonlol
maroonlolOP3y ago
Ezlanding
Ezlanding3y ago
@Abdul Raheem Nazir change int shift3 to double shift3 You are saving the result of Round, a double number (a number with decimals) in shift3, an integer number (a number without decimals). Since they aren’t the same type, it throws an error
maroonlol
maroonlolOP3y ago
Thank you that worked also i had to changee wher it says number into root because it was rounding the input not the actual root of the number
maroonlol
maroonlolOP3y ago
it is completly working now
Ezlanding
Ezlanding3y ago
👍
Want results from more Discord servers?
Add your server