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 trial

C#

help with "if else"

My if else statements are not working. 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 <= 10){
      Console.WriteLine("Well it's better than nothing, am I right?");
      }
      else if (minutes <= 30){
      Console.WriteLine("Way to go hot stuff!");
      }

     else if (minutes <= 60){
      Console.WriteLine("Wow, you must be a ninja warrior in training!");
      }

      else if (minutes <= 80){
      Console.WriteLine("Okay, now you're just showing off!");
      }

      else if (minutes <= 100){
      Console.WriteLine("Just stop before you hurt yourself!");
      }

      else if (minutes <= 120){
      Console.WriteLine("What you are doing can not be healthy!");
      }

      else if (minutes <= 240){
      Console.WriteLine("Please stop now...");
      }

      else if (minutes <= 260){
      Console.WriteLine("I am seriously trying to help you, stop exercising!");
      }

      else if (minutes <= 280){
      Console.WriteLine("I am starting to run out of things to say to you...");
      }

      else if (minutes <= 300){
      Console.WriteLine();
      }

      else if (minutes == 666){
      Console.WriteLine("You have dialed DOOM services please stand by....*Hold music that will never end*");
      }
      else {Console.WriteLine("I understand that you are not going to listen to me so i give up on you I have plenty of other people to help get fit... This is you fault... I tried to warn you... but NO... you haaad to do more exercise... Good BYE!");}


      // Add minutes exercised to a total...
       runningTotal = runningTotal + minutes;

      // Display the current total on screen...
      Console.WriteLine("You've entered " + runningTotal + " minutes");

      } 
                  // Repeat until the user quits.
        }



      }                
    }

1 Answer

Steven Parker
Steven Parker
231,248 Points

It looks like your main issue might be that "minutes" is declared inside a conditional block but referenced in the outer context.

You might consider expanding the "else" conditional around the initialization of "minutes" so that it includes the "if...else" chain and the other code that needs access to "minutes".