Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohan Berg
Courses Plus Student 5,352 PointsC# Final Compilation Errors
When I try to compile my C# program, I receive the following error message:
- "Program.cs(13,21): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer"
- "Program.cs(25,32): error CS0019: Operator
<' cannot be applied to operands of type
int' and `string'"
I have tried several times, but I have not been able to determine the source of this problem.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
while(true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var yay = Console.ReadLine();
if (yay.ToLower()= "quit")
{
break;
}
try{
var run_time = int.Parse(yay);
//var i = 0;
if(run_time <= 0)
{
Console.WriteLine("Enter a positive number!");
continue;
}
for(int x = 0; x < yay; x++)
{
Console.WriteLine("Yay!");
}
}
catch (FormatException)
{
Console.WriteLine("Not a valid number.");
continue;
}
}
}
}
}
1 Answer
Steven Parker
231,210 Points"Program.cs(13,21): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer"
if (yay.ToLower()= "quit")
You probably intended a comparison ("==") there instead of an assignment.
"Program.cs(25,32): error CS0019: Operator <' cannot be applied to operands of typeint' and `string'"
for(int x = 0; x < yay; x++)
The variable "x" is an int, but "yay" contains a string. Did you mean to compare "x" with "run_time" instead?
Also be aware that a program that follows the challenge instructions will only ask for input one time, and either print "Yay!"s or an error message. But either way it should end.
Johan Berg
Courses Plus Student 5,352 PointsJohan Berg
Courses Plus Student 5,352 PointsI managed to solve the "The left-hand side of an assignment must be a variable, a property or an indexer" problem by doing what you suggested, but when I replaced the "yay" variable in the for loop with "run_time", I received the following error message:
"System.NullReferenceException: Object reference not set to an instance of an object at Treehouse.CodeChallenges.Program.Main () [0x00010] in <7e87a22d2c3d4d709e9df60edcfbb43b>:0 at MonoTester.Run () [0x000b5] in MonoTester.cs:91 at MonoTester.Main (System.String[] args) [0x00013] in MonoTester.cs:28"
I have not changed anything else aside from those two aforementioned parts of the program.
Steven Parker
231,210 PointsSteven Parker
231,210 PointsDon't overlook the third suggestion. You still have an outer loop that prevents the program from ending until "quit" is entered. This is not part of the instructions.