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 trialJim Conachan
2,514 PointsC# error
Getting the CS1525 unexpected symbol '{' error. I feel like all curly braces are correct. Opening and closing curly braces equal 6 each. Error reads: Program.cs (13,14). These lines appear correct to me. Where am I going wrong?
https://teamtreehouse.com/library/if-else
Code:
using System;
namespace Treehouse.FitnessFrog { class Program { static void Main() { int runningTotal = 0; bool keepGoing = true;
while (keepGoing)
{
Console.Write("Enter how many minutes you exercised or type \"quit\" to exit: ");
string entry = Console.ReadLine();
if (entry == "quit")
{
keepGoing = false;
}
else
{
int minutes = int.Parse(entry);
runningTotal = runningTotal + minutes;
Console.WriteLine("You've entered " + runningTotal + " minutes");
}
}
Console.WriteLine("Goodbye");
}
}
}
10 Answers
Steven Parker
231,248 PointsIt works for me.
I just pasted in your code from above, and it compiled without error (and ran, too).
To enable a more complete and accurate analysis, make a snapshot of your workspace and post the link to it here.
Jim Conachan
2,514 PointsIs it possible there's something up with my Treehouse Workspaces? I just did it again and typed: clear && mcs Program.cs && mono Program.exe ... and still get the error.
I don't know how to make a snapshot of my workspace, nor can I paste in a screen shot.
Steven Parker
231,248 PointsFYI: Screen shots are generally not very useful for diagnosing code problems.
Jim Conachan
2,514 Pointsdoes this allow you in to my workspace?
Steven Parker
231,248 PointsThat's a direct URL to your workspace, it's temporary and only exists while you are using it.
But you can use the snapshot function in the workspace and provide the link to that.
Click on the word snapshot for a video on making them, or just use the little "camera-ish" icon in the upper right of your workspace screen (next to the "fork" and "preview" icons).
Jim Conachan
2,514 PointsI think I've done it. Thanks for the link to snapshot.
Steven Parker
231,248 PointsRemember that C# is a case-sensitive language.
The code you posted above is fine, but the one in your workspace has "WHILE
" (in upper case) on line 12 instead of "while
".
Change it to lower case (like the code above) and it will build without errors.
Jim Conachan
2,514 PointsI did that and it still says I have a curly brace as an unexpected symbol. This is very frustrating. Here's a snapshot having changed WHILE to while. Is it possible there's something up with my workspace? I'm running Windows 7. https://w.trhou.se/hr1evilxxh
Steven Parker
231,248 PointsThe code in the new snapshot builds without error. The workspace provides it's own environment, so it should not be affected by the operating system on the computer you run the browser from.
First, make sure you saved your edits in your original workspace and try building again. It it still doesn't work, try this:
Open the snapshot yourself, choose "fork snapshot" to convert it back into a workspace, give it a new name (or just add "snapshot" to the title), and then try building in the forked workspace. If it works but the original does not, try opening the original and comparing the source for possible differences.
If none of that helps, this might be an issue you'll need to contact Support about.
Jim Conachan
2,514 PointsThanks Steven. That worked! First time since the course started.
From the beginning, some of the code wasn't running right. Example, this is the first time I've been able to see added minutes total correctly. I think contact Support about this as suggested, so I can see work compile and run properly.
Thanks again for your patience.
Jim
Steven Parker
231,248 PointsGlad to help. But I'm curious — which suggestion was it that fixed the issue?
Jim Conachan
2,514 PointsThis one:
Open the snapshot yourself, choose "fork snapshot" to convert it back into a workspace, give it a new name (or just add "snapshot" to the title), and then try building in the forked workspace.
Steven Parker
231,248 PointsInteresting. And were you able to find any differences when comparing the source to the original workspace? What about completely replacing the original workspace source with the one from the snapshot fork?
Jim Conachan
2,514 PointsIf by replacing the source, you mean erase the code and paste in what we knew to be work, yes, I did. But there was no difference anyway. It's something with my workspace I think.
Steven Parker
231,248 PointsYou might want to go to the Workspaces page, delete the workspace, and then re-launch it from inside the course. Be sure to download any work you'd like to keep first, though!
Jim Conachan
2,514 Pointsthanks Steven. I'll do that before submitting a ticket and test. Treehouse has taken a back seat to actual work today, so sorry for any delayed responses. You've been really helpful and I'm grateful.
Jim