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 Final

Henry Camacho
Henry Camacho
1,735 Points

stuck on a code challenge

i know that the code attached is wrong but i have tried a few different approaches not to succeed. i am not sure how to go about printing a string using an int that comes from the input

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            bool zz = true;
            while (zz)
            {

            Console.Write("Enter the number of times to print \"Yay!\": ");
            int entry;
            entry = Console.ReadLine();
            if (entry == string)
            {
                Console.WriteLine("not a valid input");
                zz = false;
            }
            else if (entry <= 0)
            {
                Console.WriteLine("not a valid input");
                continue;
            }
            else if (entry > 0)
            {
                Console.Write();
            }
            }
        }
    }
}

1 Answer

Jon Wood
Jon Wood
9,884 Points

A couple of things I see:

  • In this line - if (entry == string), the compiler won't let you explicitly check a variable against a type (there are a few ways to do this, though).
  • Also, you need to parse the entry from a string to an int in order to do the other if statements. You can use int.Parse for that.

Hope that helps, but let me know if you need more help!