+ 1
Fix the code
Hello there, Take a look at the program below. There are some methods declared after the main. Your first input is index, second one is length of side/diagonal/height. It works correctly, however if you type doubles, an error is found. I don't really get it. So, what are your suggestions for allowing the program to take doubles in too? Could the reason be void instead of int when declaring methods? (and would return key be useful here?) I've tried declaring side, dg, t, o variables as doubles, but it didn't work. The methods have double type parameters. Looking forward to your simple enough suggestions. EDIT: The code is fixed, but feel free to suggest other changes too! https://code.sololearn.com/cT7jZu6wjVx3/?ref=app
5 ответов
+ 3
Of course.
int index = Convert.ToInt32(Console.ReadLine())
double side = Convert.ToDouble(Console.ReadLine());
+ 2
If type double, you need to convert to double, and store it in double variable.
double index, side, t, dg, o;
index = Convert.ToDouble(Console.ReadLine());
+ 2
2/ Math.sqrt(n) will result accurate answer. If you don't need, or rounding value then both result same.
You can use anyone, depends on the required result. Both ways works fine.
+ 1
I'd want my index as an integer though. Can I get others declared as doubles anyway?
+ 1
Great! Doubles work now.
One more thing, numbers inside methods don't have to be left as approximations. I could use (2 / Math.Sqrt(3)) or 1.1547, what's better? I think it's both.