0

Area of a Circle in Basic Concepts C#

Guys, Can someone help me to get through the last elements in a C# course? I wanted to start doing the programming parts at the end of each segment but the first one already blocks me out. There are 3 first steps do do but nothing gets me throught all of them, then to unlock 4 and 5, so maybe I can get it validated and move forward. declaring 5, the area of a circle gives you 78,5, ok done, step 2, I add the next part of code, r=6.4, area = whatever... what is wrong with this thing or what is wrong with me? :) Any hints how to pass it through please? Here is 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 radius1, radius2, radius3; int r1 = 5; radius1 = Convert.ToDouble(pi * r1 * r1); Console.WriteLine(radius1); double r2 = 6.4; radius2 = Convert.ToDouble(pi * r2 * r2); Console.WriteLine(radius2); int r3 = 10; radius3 = Convert.ToDouble(pi * r3 * r3); Console.WriteLine(radius3); } } }

12th Mar 2021, 6:14 PM
Sławomir Majchrzak
Sławomir Majchrzak - avatar
5 Respuestas
+ 2
You need to declare one variable as an input instead of many variables. radius = Convert.ToDouble(Console.ReadLine());
12th Mar 2021, 6:22 PM
Simba
Simba - avatar
+ 2
Because it's not necessary to add extra prompt messages in your solutions. Also, inputs are tested by compiler itself. You can check them in test cases :)
13th Mar 2021, 12:46 AM
Simba
Simba - avatar
+ 1
Thank you Simba, It works in VS but not inside the Sololearn code window, actually I don’t even get to input my value... using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Egzamin_1s { class Program { static void Main(string[] args) { const double pi = 3.14; double radius; Console.WriteLine("What's your input?"); radius = Convert.ToDouble(Console.ReadLine()); Console.WriteLine(pi * radius * radius); } } }
12th Mar 2021, 6:59 PM
Sławomir Majchrzak
Sławomir Majchrzak - avatar
+ 1
Well, ok I got it through when I changed the input line to comments: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main() { const double pi = 3.14; double radius; //Console.WriteLine("What's your input?"); radius = Convert.ToDouble(Console.ReadLine()); Console.WriteLine(Convert.ToDouble(pi * radius * radius)); } } } This is so weird !
12th Mar 2021, 7:14 PM
Sławomir Majchrzak
Sławomir Majchrzak - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Egzamin_1s { class Program { static void Main(string[] args) { const double pi = 3.14; double radius=double.Parse(Console.ReadLine()); Console.WriteLine(pi * radius * radius); } } }
30th Aug 2022, 9:58 AM
Arsen Belluyan
Arsen Belluyan - avatar