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
What does the error say?
this is what it says
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 callThat 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?
Does shift2 not do that?
^ @Abdul Raheem Nazir
Unfortunately no and I'm not sure why not
see here, this outputs 1.2
var i = Math.Round(1.239482823381, 1);
Console.WriteLine(i);
What does it output for you?it outputs the long decimal when I wanted only to one decimal place
@Abdul Raheem Nazir you round
number
, but you print root
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
Thanks you too! 👍
O'm sorry im back again😅
It is printing the value entered now and not calculating the square toot
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 enteredI think this is what you meant however I have tried that but then i get another error
@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 errorThank 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
it is completly working now
👍