Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Arithmetic Calculator challenge problem, I cant exit the program for some reason.

Hi, This is my code:

using System;

namespace TreeHouse.Calculator
{
class Calculator
{
static void Main()
{
var totalResult = 0.0;

while(true)
{
try
{
var number = double.Parse(entry);
if(entry.ToLower() == "quit") {
break;

}

Console.WriteLine("Please enter an operation [+ - / * ]: ");
if(entry2.ToLower() == "quit") {
break;
}

var number2 = double.Parse(entry3);
if(entry3.ToLower() == "quit") {

break;
}

if(entry2 == "+")
{
totalResult = number + number2;
}

else if(entry2 == "-")
{
totalResult = number - number2;

}

else if(entry2 == "*")
{
totalResult = number * number2;

}
else if(entry2 == "/")
{
totalResult = number / number2;

}

Console.WriteLine("the result is: {0}", totalResult);

}

catch(FormatException) {
continue;

}

}

}

}

}

when i try to exit the program by typing 'quit', i get the messege from my exception, I checked alot of times and i can't find the problem why my 'if' statment are not working..

another problem i have is when i type a string or a number in a operator prompt it pass and in result the "final result" become 0.. any ideas how to fix this?

:D?

****** UPDATE ******

I somehow tried to get all this code outside the 'try' check

using System;

namespace TreeHouse.Calculator
{
class Calculator
{
static void Main()
{
var totalResult = 0.0;
Console.WriteLine("what is your name? : ");
Console.WriteLine("Welcome to the program {0}!", name);

while(true)
{
if(entry.ToLower() == "quit") {
Console.WriteLine("Goodbye, {0}", name);
break;

}

Console.WriteLine("Please enter an operation [+ - / * ^ ]: ");
if(entry2.ToLower() == "quit") {
Console.WriteLine("Goodbye, {0}", name);
break;
}

if(entry3.ToLower() == "quit") {
Console.WriteLine("Goodbye, {0}", name);
break;
}

try
{
var number = double.Parse(entry);
var number2 = double.Parse(entry3);

if(entry2 == "+")
{
totalResult = number + number2;
}

else if(entry2 == "-")
{
totalResult = number - number2;

}

else if(entry2 == "*")
{
totalResult = number * number2;

}
else if(entry2 == "/")
{
totalResult = number / number2;

}

else {
totalResult = Math.Pow(number, number2);

}

Console.WriteLine("the result is: {0}", totalResult);

}

catch(FormatException) {
continue;

}

}

}

}

}

It's working now but i dont fully understand why i had to get this code outside of the "TRY" check.

and i still didnt fixed the other problem i mentioned before. The reason are the following codes

var number = double.Parse(entry);
if(entry.ToLower() == "quit") {
break;

}

//....