+ 1

C# "Area of a Circle" Test Cases?

I'm kinda confused with the output for the test cases. I go with: double Radius = Convert.ToDouble(Console.ReadLine()); double Area = Math.PI * Radius * Radius; Which is working great but the output seems to be slighty different for every test case. Is there something I'm not thinking of right now? Example: "Input 5, expected output 78.5" THEN "Input 6.4, expected output 128.6144" and so on. I'm trying different things like Math.Round or Convert.ToSingle but I don't see a solution to pass every test case at once. One case doesn't even display decimal numbers. What do I miss?

6th Sep 2021, 8:38 AM
Aleksander Weyand
Aleksander Weyand - avatar
3 Réponses
+ 5
Aleks Weyand , it's written in the task description "the program declares a constant pi => 3.14". Instead of this you are using Math.PI which has more numbers after the decimal point, that's why the result is not the same.
6th Sep 2021, 8:44 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
I think in that test u need to declare pi, try using, const double pi = 3.14
6th Sep 2021, 8:44 AM
CodeSmith
CodeSmith - avatar
+ 2
I just changed it to: double Area = pi * Radius * Radius; Now it's working fine. Thank you guys.
6th Sep 2021, 9:04 AM
Aleksander Weyand
Aleksander Weyand - avatar