elizac
elizac

Reputation: 11

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

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);

Upvotes: 0

Views: 865

Answers (2)

Netr&#229;m
Netr&#229;m

Reputation: 487

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;

Upvotes: 0

MonsterBasket
MonsterBasket

Reputation: 133

Would it not just be this?

input = Math.Round(input) * y;

Upvotes: 0

Related Questions