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) Console I/O Console I/O

Vygandas Razhas
PLUS
Vygandas Razhas
Courses Plus Student 2,422 Points

Can someone help me complete the code? I'm lost.

How do I finish this question? What am I doing wrong here?

CodeChallenge.cs
string var = bookTitle;
System.Console.Write("Enter a book title: ") ;
System.Console.ReadLine bookTitle;

2 Answers

string bookTitle;
System.Console.Write("Enter a book title: ") ;
bookTitle = System.Console.ReadLine();

A couple of things I would like to mention. The first is that you are declaring two variable types in the beginning, then initializing it without giving it a name. You can call a variable type var or string to make it work for this assignment, but NOT both. Declare one variable type per variable. I just made my bookTitle variable an uninitialized string since being specific helps. I could have given it a value, but I did later in the next step.

After that, you need to make sure that you are passing the result from the System.Console.ReadLine() function into the bookTitle variable. The way you wrote it, System.Console.ReadLine() is not called because you need the parenthesis but nothing else. REMEMBER, the left part of an = sign takes on the value of whatever the right calculates to, so if you decide to System.Console.WriteLine what's stored in the variable bookTitle after, it should spit out whatever content the user inputs on the bookTitle = System.Console.ReadLine(); line of code.

Hope this helps. Let me know if you have further questions, of if this still doesn't make sense.

Vygandas Razhas
Vygandas Razhas
Courses Plus Student 2,422 Points

May you please rephrase the answer in simpler terminology? Thank you, I appreciate it!

3 Things.

  1. Declare a variable using one variable type and ONLY one (You used two). To do this, put it next to a SINGLE variable type like this:

    string bookTitle;
    

    Or perhaps this

  2. Record user input by using System.Console.ReadLine(). When you use this function, the information can be passed into a variable of type string by setting the variable equal to System.Console.ReadLine(); .

    bookTitle = System.Console.ReadLine();
    

    Now you can do something with the user's input using the bookTitle variable, but only if you write the variable on the left of the equals sign.