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# C# Basics (Retired) Perfect Variable Scope

Ahkeem Lang
Ahkeem Lang
16,358 Points

I'm not sure how to tackle this...

I'm not entirely sure how to go about solving this error?

using System;

namespace Treehouse.FitnessFrog { class Program { static void Main() { double 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.ToLower == "quit") 
      {
        keepGoing = false;
      }
      else
      {
        try
        {
           double minutes = double.Parse(entry);

           if(minutes <= 0)
        {
          Console.WriteLine(minutes + " 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 you're just showing off!");
        }
      }
           catch(FormatException)
        {
          Console.WriteLine("That is not valid input.");
          continue;
        }

      }



      // Add minutes exercised to total
      runningTotal = runningTotal + minutes; // this is line 56

      // Display total number of exercised to the screen
      Console.WriteLine("you've entered " + runningTotal + " minutes");


      // Repeat until the user quits

    Console.WriteLine("Goodbye");
      }
  } 

}

Program.cs(19,21): error CS0019: Operator ==' cannot be applied to operands of type method group' and string' Program.cs(56,27): error CS0103: The nameminutes' does not exist in the current cont ext

1 Answer

Dennis Smith
Dennis Smith
1,036 Points

To address the first error at line 19, you need to add () at the end of ToLower such as:

      if (entry.ToLower() == "quit") 

The second error is because you have a couple misplaced lines. Move lines 55 to 59 under line 43. This way they are in your try block. It should look something like this:

          Console.WriteLine("Okay, now you're just showing off!");
        }
        // Add minutes exercised to total
        runningTotal = runningTotal + minutes; // this is line 56

        // Display total number of exercised to the screen
        Console.WriteLine("you've entered " + runningTotal + " minutes");
      }
        catch(FormatException)