Geometry | Sololearn: Learn to code for FREE!

+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?

8/6/2022 7:58:51 AM

SilentPlays

2 Answers

New Answer

+2

= is an assignment operator. == is an comparison operator.

+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/