+ 11

Area of a circle in C#

Please help with how to do this?

16th Dec 2020, 12:56 PM
Carla Lee
11 Answers
+ 12
You need to declare area like double area since radius is also double. Also Convert.ToDouble() should be applied to Console.ReadLine() because what it does it to convert the input to double. radius = Convert.ToDouble(Console.ReadLine()); double area = pi * radius * radius; Console.WriteLine(area);
16th Dec 2020, 2:11 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 8
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; //your code goes here radius = Convert.ToDouble(Console.ReadLine()); double area = pi * radius * radius; Console.WriteLine(area); } } }
5th Feb 2021, 12:36 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
+ 3
Oli, acá les dejo otra alternativa para resolverlo: radius = Convert.ToDouble(Console.ReadLine()); // Get the exponent of radius double exp = Math.Pow(radius, 2) * pi; Console.WriteLine(exp);
13th Jan 2021, 1:53 AM
Elisa Rojas
Elisa Rojas - avatar
0
Thanks for the help. Here is the code I have im not sure where im going wrong! const double pi = 3.14; double radius; Console.Writeline("Enter Radius: "); (Console.Readline()); area = Convert.ToDouble Math.PI * radius * radius; Console.Writeline"Area of Circle: "); Conesole.Readkey();
16th Dec 2020, 1:18 PM
Carla Lee
0
thanks so much for explaining, this makes sense!
16th Dec 2020, 2:42 PM
Carla Lee
0
I'm getting the first test case right, but I am not sure how to get the other two test case results in order to complete the mini project. How do I execute all three area tests? edit- I've figured my own question out. I need to first convert the radius input (which is found by using Console.Readline() to a double, and then using that to determine the value of the area before using Console.Writeline to declare the output. test passed.
21st Mar 2021, 6:07 AM
Karl
Karl - avatar
0
This may seem like a silly question but why do we need to convert the radius input to double if the radius was already declared a double? I just feel like its being declared twice.
9th Jul 2021, 5:55 PM
Timisha Patterson
Timisha Patterson - avatar
31st Oct 2021, 5:14 PM
Elia John
Elia John - avatar
0
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 = Convert.ToDouble(Console.ReadLine()); double area = pi * radius * radius; Console.WriteLine(area); } } } We use Console.ReadLine() for input. This function means the user will type the input then use Enter to apply. For emxample Console.ReadLine() and we type 5 then enter. The program will run like Console.ReadLine(5). Convert.ToDouble will double the Console.ReadLine(5). This function will replace the 5^2 or 5*5
15th May 2022, 5:05 PM
Anh Khôi
- 1
area = πr² = π. input here ² 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; //your code goes here radius = Convert.ToDouble(Console.ReadLine()); double area = pi * (radius * radius); Console.WriteLine(area); } } }
21st Jun 2021, 7:00 AM
Ali Ebadi
Ali Ebadi - avatar
- 2
pi*radius*radius and you get the area.
16th Dec 2020, 1:04 PM
你知道規則,我也是
你知道規則,我也是 - avatar