+ 4

Area of a circle??

I don't understand where's the issue. I'm trying to make a program that takes the radius and the calculates the area. Here's my 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; double Area(double r){ r = radius; double area = pi * r * r; Console.WriteLine(area); return area; } } } }

16th Dec 2020, 12:17 AM
Ezequiel Navarrete Caparros
Ezequiel Navarrete Caparros - avatar
14 Réponses
+ 5
Here's how I solved it 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 r = radius; double area = pi * r * r; Console.WriteLine(area); } } }
16th Dec 2020, 12:57 AM
Ezequiel Navarrete Caparros
Ezequiel Navarrete Caparros - avatar
+ 4
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 r = radius; double area = pi * r * r; Console.WriteLine(area); } } }
6th Sep 2021, 10:51 PM
Mahdi Tahir Ahmat
Mahdi Tahir Ahmat - avatar
+ 2
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) {//CALCULE EL AREA DE UN CIRCULO PRUEBA 1 const double pi = 3.14; double radius; radius = Convert.ToDouble(Console.ReadLine()); double r = radius; double area = pi * r * r; Console.WriteLine(area); } } No se si esta bueno :v, y si no pues me dicen para saber Con esto Pase la prueba 1 :v suerte...
15th Jan 2021, 3:55 AM
Darwin Noe Ordoñez Martinez
Darwin Noe Ordoñez Martinez - avatar
+ 1
Just found the issue. I was missing the input from the user and the Convert.ToDouble
16th Dec 2020, 12:27 AM
Ezequiel Navarrete Caparros
Ezequiel Navarrete Caparros - avatar
0
Hi, it seems like you created a function called “Area” but you never called it. After the closing of “Area” function write “Area(<your radius>);”, also replace the line “r = radius;” with “radius = r;” because you want to change the value of “radius” and not “r” because “r” is just a temporary parameter. If you are still having trouble I’m free here.
16th Dec 2020, 12:29 AM
Frumkin
Frumkin - avatar
0
double pi = 3.1416; double radius; double area; //READ Console.Write("Enter the radius: "); radius = Convert.ToDouble(Console.ReadLine()); //we use convert because all the input // CALCULATE area = pi * Math.Pow(radius, 2); //^ Above code is same as 5*5 = 25 * 3.1416 which = the area 78.5 //PRINT Console.WriteLine("The radius of the circle is {0} and the area is {1} ", radius, area); I did it like this which outputs what it wants but it didn't let me pass the test. Had to come here and see how you guys did it then paste in some ones code.
30th Apr 2021, 8:19 AM
Boss Zeus
Boss Zeus - avatar
0
nobody asked you to write area, but you need an output an area. So stick with the output as if it's already area.Don't redefine anything just delete few letters from radius to 'r'. Also it asked convert to Double, otherwise it won't work. This works perfectly, and is according to previous lessons, don't reinvent bicycle: const double pi = 3.14; double r = Convert.ToDouble(Console.ReadLine()); //inputs r Console.WriteLine(r * r * pi); //outputs area
16th May 2021, 7:11 PM
Alvydas Jokubauskas
Alvydas Jokubauskas - avatar
0
Answer: 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 r = radius; double area = pi * r * r; Console.WriteLine(area); } } }
8th Jul 2021, 4:11 AM
Trần Văn Hải (HAITV13)
Trần Văn Hải (HAITV13) - avatar
0
Why do we have to convert to double? :/ what does it do. Also how does it know that r is 5,when it's not declared like pi = 3.14
9th Jul 2021, 10:38 PM
Sebastian
Sebastian - avatar
0
20th Aug 2022, 4:30 AM
MUKILAN VIDYAAKAR
MUKILAN VIDYAAKAR - avatar
- 1
La he completado con este código: 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 = 5; radius = Convert.ToDouble (Console.ReadLine ()); double r = radius; double area = (pi * r * r); Console.WriteLine(area); } } }
4th Feb 2021, 6:32 PM
Adrià Vilà Martin
Adrià Vilà Martin - avatar
- 1
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; double area; radius = Convert.ToDouble(Console.ReadLine() ); area = pi*radius*radius; Console.WriteLine(area); Console.ReadLine(); } } }this is simpler u don't have to write double radius double area every time just specify once that area is a double and it will follow it for the rest of the code
12th Mar 2021, 5:47 AM
Sagar Sir
Sagar Sir - avatar