left-hand side of an assignment must be a variable, property or indexer when trying to round variable and use operator

690 Views Asked by At

Code is returning: "The left-hand side of an assignment must be a variable, property or indexer"

I'm still new to C# (coming from python), but I understand this issue, however I've got no clue how to fix it

I essentially want to have input initially equal x round x each cycle and multiply that rounded number by input y:

Console.WriteLine ("input x:");
int inputx = Convert.ToInt32(Console.ReadLine());

Console.WriteLine ("input y:");
double y = double.Parse(Console.ReadLine());

double input = inputx;

for (int i = 0, i < a, i++)
    Math.Round(input) *= y;

Console.WriteLine ("Value output: {0}", input);
2

There are 2 best solutions below

0
Netråm On

The error comes from the line in the loop. What it's trying to do is to multiply Math.Round(input) and y, and then assign the result to Math.Round(input) which isn't a variable, it's and expression.

To get it to work you'll have to separate the multiplication and the assignment, instead using the following line.

input = Math.Round(input) * y;
1
MonsterBasket On

Would it not just be this?

input = Math.Round(input) * y;