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) Perform if / else

Where should you place Console.WriteLine("Goodbye"); for this video?

I placed it in the code for the if statement:

if (entry == "quit") { keepGoing = false; Console.WriteLine("Goodbye"); } When I followed the video it kept saying goodbye after I entered the amount of minutes

Hendrik Heim
Hendrik Heim
1,012 Points

Hey Victor. Please provide your full code

4 Answers

Hendrik Heim
Hendrik Heim
1,012 Points

Your code seems correct to me. Did you try running your code in an IDE for example Visual Studio?

Alternatively, try this:

While(entry != "quit") { // handle input }
//finishing message after loop
Console.WriteLine("Goodbye");

Note you have to declare and initialize entry before entering the loop.

Daniel Atonge
Daniel Atonge
4,769 Points

The code is ok with no problems. I ran both on Visual Studio. I think the confusion comes in with the ending curly brackets. As Hendrik earlier said: While(entry != "quit") { if () { } else { //Take Note } // handle input }//ending curly bracket for the While-loop //finishing message after loop Console.WriteLine("Goodbye"); Thanks

//full code

using System; 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:");

        //Store this in a variable...This collectys user input

        string entry = Console.ReadLine();

        if (entry == "quit") 
        {
          keepGoing = false;
          Console.WriteLine("Goodbye");
        }else {

        int minutes = int.Parse(entry);

          if(minutes <= 10){
            Console.WriteLine("Better then 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!");

          }else 

          {
           Console.WriteLine("Okay, now you are just showing off!"); 

          }

        runningTotal = runningTotal + minutes;

          //Add minutes exercised to total
          //Display the total number of minutes exercised to the screen

        Console.WriteLine("You've entered " + runningTotal + " minutes");
          //Repeat until the user quits
        }

      }   


    }
}

The code runs but when I ran the code following the Video the "Goodbye" text came after I entered the exercise value. So i would type 35 and it would say Goodbye and then I would type 25 and it would say goodbye. All I was trying to say is that there seems to be an error in the code from the video.