+ 6

[Solved] C# Course Project Doubt

In this code I can get the area if the input is an integer but when it is a float it displays an error. Why? Please help Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { const double pi = 3.14; double radius; radius = Convert.ToInt64(Console.ReadLine()); //your code goes here // Console. Console.WriteLine(pi*( radius * radius )); } } }

27th Dec 2020, 7:23 AM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
5 odpowiedzi
+ 4
Ayush Kumar Thanks bro
27th Dec 2020, 7:27 AM
LordOfThunder [Inactive]
LordOfThunder [Inactive] - avatar
+ 2
Maybe you have error coz you have radius as double but your input is converting to int?
27th Dec 2020, 9:13 PM
Mr Wolfy
Mr Wolfy - avatar
+ 1
Exactly what Mr Wolfy said. You can not put directly int64 into double. You can calculate between double and int but you can not put int into double like you did. Instead of Convert.ToInt64(),use Convert.ToDouble(). That way you can add user input to your radius variable with type double.
28th Dec 2020, 5:03 PM
Bogdan Parubok
Bogdan Parubok - avatar