> For the complete documentation index, see [llms.txt](https://raviram.gitbook.io/c-programing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://raviram.gitbook.io/c-programing/c-fundamental-concepts/user-input.md).

# User Input

## User Input

To accept input from user, We use `Console` class `Console` has a function called `ReadLine()` which tells the OS to ask for user input. We shall discuss `using` and classes later:

<pre class="language-csharp"><code class="lang-csharp"><strong>using System; 
</strong>
Console.ReadLine();
</code></pre>

After we read it, we can convert the data into required format using Convert class:

```csharp
Convert.ToInt32(Console.ReadLine())
```

### Exercise

Ask the user for two his birth year in `yyyy` format and calculate his age and display:

```csharp
using System;

 class Program
 {
    static void Main(string[] args)
    {
        Console.WriteLine("Enter your YOB:");
        int yob = Convert.ToInt32(Console.ReadLine());
        

        //Do not modify code below!
        int age = 2022 - yob;
        Console.WriteLine($"You are {age} years old!");        
    }
}
```

We could do the same for a decimal type number as well:

```csharp
Convert.ToDouble(Console.ReadLine());
```

### Exercise

Ask the user his weight and display it:

```csharp
using System;

 class Program
 {
    static void Main(string[] args)
    {
        Console.WriteLine("Enter your weight:");
        double weight =  /*todo - get from user */

        //do not change code below:       
        Console.WriteLine($"You are {weight} kgs!");        
    }
}
```
