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

Errors not matching ones in video lesson on "if" Statements in C# Basics

Hello, I've followed the code in the instruction and the errors I am getting are different from the errors that the instructor says I should be getting around the 5:53 mark after placing the variable declaration before the first IF block. My code looks identical to that in the video. What's wrong?

Snapshot of my code in workspace link

Link to video: link

Thanks in advance!

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, Ra Bha! It's not quite identical :smiley: First, and most importantly, your code is entirely missing the Main method in Program.cs. This is required by any C# program. It tells C# where your program should begin. Without it, the code will not compile.

Secondly, on line 9, you accidentally typed Readline() instead of ReadLine(). Note the capitalization on the "L". Everything here is case-sensitive.

Your ending Program.cs file should look like this to replicate the errors the teacher has:

using System;

class Program
    static string Ask(string question) 
        Console.Write(question + " ");
        return Console.ReadLine();  // You misspelled ReadLine here

    static double Price(int quantity)
        double pricePerUnit;
        if (quantity >= 100) 
          pricePerUnit = 1.5;
        if (quantity >= 50)
          pricePerUnit = 1.75;
        if (quantity < 50)
          pricePerUnit = 2;
        return quantity * pricePerUnit;

    static void Main()  // All of this method is missing in your code
        Console.WriteLine("Welcome to the cat food store!");

        string entry = Ask("How many cans are you ordering?");
        int number = int.Parse(entry);
        double total = Price(number);
        Console.WriteLine($"For {number} cans, your total is: ${total}");

Hope this helps! :sparkles: