+ 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; } } } }
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);
}
}
}
+ 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);
}
}
}
+ 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...
+ 1
Just found the issue.
I was missing the input from the user and the Convert.ToDouble
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.
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.
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
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);
}
}
}
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
0
- 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);
}
}
}
- 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