0

Help!

I am trying to learn C#. I’m new to coding, so I’m still figuring out how it all works. The first project asks you to build a code that will read the input (radius of a circle) and then formulate the area of a circle. I cannot for the life of me figure out what is wrong with this code. Please, someone help!! https://code.sololearn.com/cK6d9HI2bGF0/?ref=app

6th Jul 2022, 7:55 PM
Omnijuice
Omnijuice - avatar
3 Réponses
+ 3
// This will help you radius = Convert.ToDouble(Console.ReadLine()); Console.Write(pi*radius*radius);
6th Jul 2022, 8:55 PM
JaScript
JaScript - avatar
+ 1
double int radius; // this is error because variable may be double type or int type but not both types.. string x = radius; // radius still uninitialzed so error int y = pi; // double to int, loss of data, error radius = Console.ReadLine(); // this will read a line of string. So input is in string format. Convert to needed destination type.. You just need a double type input. And formula is pi * radius * radius for output.. // for reading input of double type value.. double radius = Convert.ToDouble( Console.ReadLine() ); Output : Console.Write( pi * radius * radius);
6th Jul 2022, 8:09 PM
Jayakrishna 🇮🇳
+ 1
https://code.sololearn.com/chtUt5UN667m/?ref=app I corrected the code so that it works now I tried to mostly Just delete unnecresary parts and change Something a little. Some Points there: -When you want a numeric input like here should you directly declare it in int with convert (See code) -Next when you make a calculation with double make the variable for the result also double.
7th Jul 2022, 1:56 AM
Felix Alcor
Felix Alcor - avatar