vendredi 29 janvier 2021

Console.ReadLine as an integer [duplicate]

Very basic question, my first day of learning C#

I am doing a tutorial from codeacademy.
Its a basic "how old are you"
enter a number and it says back to you "you are X years old!"

The code is

using System;

namespace GettingInput
{
class Program
{
static void Main()
{
Console.WriteLine("How old are you?");
string input = Console.ReadLine();
Console.WriteLine($"You are {input} years old!");
}
}
}

I want the string as an int (no text just numbers)
and an IF statement to return "you are x years old" if X <= 140
and else would be "you arent that old" for X > 140.

I tried

int input = Console.ReadLine();

        bool x =< 120 true; 
       
        if (input > "120");
      {
           Console.WriteLine($"You are not {input} years old!!");<br>
        }
  else if  (input =<"120")
        {
            Console.WriteLine($"You are {input} years old!");

Aucun commentaire:

Enregistrer un commentaire