+ 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 )); } } }
5 Antworten
+ 4
Ayush Kumar
Thanks bro
+ 2
Maybe you have error coz you have radius as double but your input is converting to int?
+ 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.