+ 3

C# Number 12

When I run the code it says that * can’t be applied to a string but I thought I converted it. What do I do? 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()); Console.Write("+pi+"*"+radius+"*"+radius+"); } } }

2nd May 2021, 11:07 PM
Firefist2004
Firefist2004 - avatar
7 ответов
+ 2
You don't need quotes or plus signs in the last line, just pi*radius*radius. Your code right now says multiply these 3 strings (which just happen to contain the names of your variables, enclosed in plus signs)
3rd May 2021, 12:37 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 3
Just as Benjamin said this code tries to multiply 3 strings it's like ("+pi+") * ("+radius+") * ("+radius+") Since it can't multiply strings it throws an error. The Write function can take numbers as an output so just type Console.Write(pi*radius*radius);
3rd May 2021, 2:15 AM
Abd-ElRahman Abdeen
+ 2
Print only the result . Either directly or give it in a variable and print
3rd May 2021, 2:42 AM
Atul [Inactive]
+ 2
Math.PI https://docs.microsoft.com/en-us/dotnet/api/system.math.pi?view=net-5.0 Math.Pow https://docs.microsoft.com/en-us/dotnet/api/system.math.pow?view=net-5.0 If you want to use .net framework. You can use Math Class. You'll get. double input = Convert.ToDouble(Console.ReadLine()); double radius = Math.Pow(input,2); Console.Write(Math.Round((Math.PI * radius),2)); Console.ReadKey(); 🌻😊🌼
11th May 2021, 9:33 PM
Monica Martinez
Monica Martinez - avatar
+ 1
Reconsider that last Console.Write command. I think the quotes don’t line up the way you want them too. It looks like you are trying to multiply three strings together. I can’t tell if those are single quotes or double quotes, but either way it’s a little off.
2nd May 2021, 11:36 PM
Jerry Hobby
Jerry Hobby - avatar
0
Bad code 🐷 moon a. 🐽 ; confusing because it doesn't distinguish between the actual radius and it's power.
13th May 2021, 7:02 AM
Abd-ElRahman Abdeen
0
you don't need quotes because It's want to multiple string and IT CAN'T TO IT!!!!!!!!
7th Jul 2023, 3:50 PM
behrad baghi