C# test | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C# test

Hello everyone. I am trying to learn C# and I got the right answer but I don't know how to implement it in a way to get all cases correct. I am trying to pass this code project. https://www.sololearn.com/learning/eom-project/1080/1016 Here is my code which gives me the first case correct but if I uncomment the other code, then I get all of them wrong but the answers are correct. Can someone help me understand why is not working? Thanks. static void Main(string[] args) { const double pi = 3.14; double radius; //your code goes here static double areaOfCircle(double radius) { return pi * radius * radius; } Console.WriteLine(areaOfCircle(5)); //Console.WriteLine(areaOfCircle(6.4)); //Console.WriteLine(areaOfCircle(10)); }

3rd May 2022, 2:29 AM
Julio Rodriguez
3 Answers
+ 2
//your code goes here .. Area of the circle radius = Convert.ToDouble(Console.ReadLine()); double area = pi * Math.Pow(radius,2); //or double area = pi * (radius*radius); Console.WriteLine(area);
3rd May 2022, 3:30 AM
SoloProg
SoloProg - avatar
+ 3
You need to get user input rather than hard code all the test
3rd May 2022, 3:30 AM
Raul Ramirez
Raul Ramirez - avatar
+ 1
// Thank you very much for the help. Raul Ramirez and SoloProg. // It really helped me understand. Appreciate it! // Wish you guys the best! // Here it is my final code after understanding in case anyone else stumble across this question. static void Main(string[] args) { const double pi = 3.14; double radius; static double areaOfCircle(double radius) { return pi * radius * radius; } radius = Convert.ToDouble(Console.ReadLine()); Console.WriteLine(areaOfCircle(radius)); }
10th May 2022, 4:24 AM
Julio Rodriguez