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 If Statements "if" Statements

Printed twice and said it didnt??!!

Program.cs
using System;

class Program
{

    static void CheckSpeed(double speed)
    {
        if (speed > 55)
        {
          Console.WriteLine("Too fast");
        }

    }

    static void Main(string[] args)
    {
        // This won't print anything.
        CheckSpeed(53);
        // This should print "too fast".
        CheckSpeed(88);
        Console.WriteLine("Too fast");

    }

}

1 Answer

you need to remove the Console.WriteLine("Too fast"); from your static void Main and only there.

You are calling a method CheckSpeed, because this is a void method it doesnt return a value. It does however return your writeline statement if the if statement is true. So the assignment text might be a bit confusing when it states : CheckSpeed will not return a value for this challenge.

so this code is the right one for the assignment -

using System;

class Program
{

    static void CheckSpeed(double speed)
    {
        if (speed > 55)
        {
            Console.WriteLine("too fast");
        }
    }

    static void Main(string[] args)
    {
        // This won't print anything.
        CheckSpeed(53);
        // This should print "too fast".
        CheckSpeed(88);
    }

}