C# C# Basics (Retired) Perform if / else

Matthew Musni
Matthew Musni
610 Points

It won't work. It Doesn't loop. What's wrong

when i run the program it doesnt have errors but it doesnt perform its function. When i type quit it says "youve entered quit minutes". I dont get it.

'''

using System;

namespace teamtreehouse1 { class MainClass { public static void Main(string[] args) {

        int runningTotal = 0;
        bool keepGoing = true;

        while(keepGoing)
        {
                // Prompt the user for minutes exercised 

            Console.Write("Enter how many times you exercised or type \"quit\" to exit: ");
            string entry = Console.ReadLine();

            if(entry == "quit")
            {
                keepGoing = false;
            }
            else
            {

                // Add minutes exercised to total

                int minutes = int.Parse(entry);
                runningTotal = runningTotal + minutes;

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

                // Repeat until the user quits 

            }

        }

        Console.WriteLine("Goodbye");

    }
}

}

'''

Matthew Musni
Matthew Musni
610 Points

ok guys i tried to create a new project in Xamarin studio then copied my code there and it worked! i don't why but it now works!

Jon Wood
Jon Wood
9,883 Points

Yep, the code looks good to me! :) When experimenting I either fire up Rider (no longer free for long, I believe) or just going to .NET Fiddle. They have better language support in terms of letting you know of compile errors as you're typing and intellisense.

1 Answer

Steven Parker
Steven Parker
171,228 Points

You must have been using different code.

The code above is not capable of the behavior you describe.