+ 1

Geometry

I am stuck on this assignment where it asks me to make it so I enter the size of the geometric figure and it calculates the area of the figure. This is the code I used: string kind = Console.ReadLine(); if (kind="square") { double a = double.Parse(Console.ReadLine()); double squareS = a * a; Console.WriteLine(squareS); } if (kind = "rectangle") { double a = double.Parse(Console.ReadLine()); double b = double.Parse(Console.ReadLine()); double rectangleS = a * b; Console.WriteLine(rectangleS); } if (kind = "circle") { double r = double.Parse(Console.ReadLine()); double circleS = r * r*Math.PI; Console.WriteLine(circleS); } if (kind = "triangle") { double a = double.Parse(Console.ReadLine()); double h = double.Parse(Console.ReadLine()); double triangleS = a*h/2; Console.WriteLine(triangleS); } and its giving me this error which I cannot fix: Cannot implicitly convert type 'string' to 'bool'. Can anyone help please?

6th Aug 2022, 7:58 AM
Emperall
Emperall - avatar
2 Antworten
+ 2
= is an assignment operator. == is an comparison operator.
6th Aug 2022, 8:20 AM
Jayakrishna 🇮🇳
+ 1
Use .Equals() method when comparing one string to another. Avoid use of equality operator for comparing string contents. You were assigning new value for <kind> when using assignment operator `=` https://www.c-sharpcorner.com/UploadFile/3d39b4/difference-between-operator-and-equals-method-in-C-Sharp/
6th Aug 2022, 8:22 AM
Ipang