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 trialMichael North
2,561 PointsUnexpected symbol 'else'
When I try to run my FitnessFrog app it tells me that else is an unexpected symbol. Please Help
Michael North
2,561 Pointsusing System;
namespace Treehouse.FitnessFrog { class Program { static void Main() { int runningTotal = 0; bool keepGoing = true;
while(keepGoing)
{
// Prompt the user for minutes exercised
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);
if(minutes <= 0);
{
Console.WriteLine(minutes + "is not an acceptable value.");
continue;
}
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 nija warrior in training!");
}
else
{
Console.WriteLine("Poop you! Stop showing off.");
}
// Add minutes exersiced to total
runningTotal = runningTotal + minutes;
// Add minutes exersiced to total
// Display total minutes exercised to the screen
Console.WriteLine("You've exercised " + runningTotal + " minutes!");
// Repeat until the user quits
}
}
Console.WriteLine("Cya later!");
}
}
}
2 Answers
Michael North
2,561 Pointsusing System;
namespace Treehouse.FitnessFrog { class Program { static void Main() { int runningTotal = 0; bool keepGoing = true;
while(keepGoing)
{
// Prompt the user for minutes exercised
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);
if(minutes <= 0);
{
Console.WriteLine(minutes + "is not an acceptable value.");
continue;
}
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 nija warrior in training!");
}
else
{
Console.WriteLine("Poop you! Stop showing off.");
}
// Add minutes exercised to total
runningTotal = runningTotal + minutes;
// Display total minutes exercised to the screen
Console.WriteLine("You've exercised " + runningTotal + " minutes!");
}
// Repeat until the user quits
}
Console.WriteLine("Cya later!");
}
}
}
Rune Andreas Nielsen
5,354 PointsHi, Michael.
You have two problems in your code.
The first issue is in the code below contains a semicolon on a if statement, that syntax is invalid.
if(minutes <= 0);
The other issue is that you are missing a curly bracket at the end of your code.
Here is the correct code.
using System;
namespace Treehouse.FitnessFrog
{
class Program
{
static void Main()
{
int runningTotal = 0;
bool keepGoing = true;
while (keepGoing)
{
// Prompt the user for minutes exercised
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);
if (minutes <= 0)
{
Console.WriteLine(minutes + "is not an acceptable value.");
continue;
}
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 nija warrior in training!");
}
else
{
Console.WriteLine("Poop you! Stop showing off.");
}
// Add minutes exersiced to total
runningTotal = runningTotal + minutes;
// Add minutes exersiced to total
// Display total minutes exercised to the screen
Console.WriteLine("You've exercised " + runningTotal + " minutes!");
// Repeat until the user quits
}
}
Console.WriteLine("Cya later!");
}
}
}
Michael North
2,561 PointsThank you very much. Thais helped a lot!
Rune Andreas Nielsen
5,354 PointsNo, problem have a nice day :)
Rune Andreas Nielsen
5,354 PointsRune Andreas Nielsen
5,354 PointsHi, Michael. Please provide a code example.