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 trialDagur Freyr Guðbrandsson
Front End Web Development Techdegree Student 2,379 PointsI have 11 errors in my code and dont know how to fix? any help? using System;
using System;
namespace Treehouse
{
class Program
{
static void Main()
{
int runnningTotal = 0;
// Prompt the user for minutes excerciced
Console.Write("Enter how many minutes you exercised or type /"quit"/ to exit: ");
if (entry == "quit)
{
string entry = Console.ReadLine();
}
else
{
int minutes = int.Parse(entry);
}
if(mintues <= 0)
Console.WriteLine(mintues + " is not an acceptable value");
else if(minutes <= 10)
{
Console.WriteLine("Better than nothing, am i right");
}
else if(minutes <=30 )
{
Console.WriteLine("Way to go hot stuff");
}
else if(minutes <= 60)
{
Console.WriteLine ("You must be a ninja warrior in training");
}
else()
{
Console.WriteLine("Okay, now your just showing off!);
}
// Add minutes excercised to total
runningTotal = runningTotal + minutes;
// Display total minutes excercised to the screen
Console.WriteLine("You've entered" + runningTotal + "minutes"); "minutes");
}
// Repeat until the user quits
}
}
and these are my errors
Program.cs(13,74): error CS1525: Unexpected symbol quit'
Program.cs(15,31): error CS1010: Newline in constant
Program.cs(16,16): error CS1525: Unexpected symbol
{'
Program.cs(18,17): warning CS0642: Possible mistaken empty statement
Program.cs(19,20): error CS1519: Unexpected symbol else' in class, struct, or interface membe
r declaration
Program.cs(20,17): error CS9010: Primary constructor body is not allowed
Program.cs(35,24): error CS1525: Unexpected symbol
)'
Program.cs(35,25): warning CS0642: Possible mistaken empty statement
Program.cs(37,74): error CS1010: Newline in constant
Program.cs(38,19): error CS1525: Unexpected symbol }', expecting
)' or ,'
Program.cs(38,20): error CS1002: ; expected
Program.cs(44,14): error CS1525: Unexpected symbol
Console'
Program.cs(44,99): error CS1525: Unexpected symbol )', expecting
;' or `}'
1 Answer
Steven Parker
231,261 PointsYou seem to have a mix of issues but the syntax errors are showing up first and stopping the build:
- on line 9 the escape sequences are using the wrong character and one is in the wrong order (try:
\"quit\"
) - on line 11 the closing quote is missing from the end of the string "quit"
- on line 33 there are stray parentheses following the else
- on line 35 the closing quote is missing from the end of the string "...showing off!"
- on line 41 everything after the (first) semicolon seems to be a partial copy of the line and doesn't belong
Once these are fixed, several scoping and order issues will be reported by the compiler. It's important for variables to be declared before they are used, and in the same (or wider) scope as they will be accessed. For example, starting on line 11:
if (entry == "quit")
{
string entry = Console.ReadLine();
}
Both issues occur here, the variable "entry" is being tested before it has been declared, and then it is declared inside the conditional code block, which would its scope would be limited and code below the block won't be able to access it.
The remaining errors will be other cases of lines out of order or variables declared in the wrong scope, or missing declarations. Hopefully you can take it from here.
Also, for any future issues, a better way to share the code is to make a snapshot of your workspace and post the link to it here.