How do i get to make it ask my name and put a date

Gift Mosala 0 Reputation points
2025-04-23T20:44:04.59+00:00

been trying to make a code to ask my name and put an exact time

This question is related to the following Learning Module

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,497 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 46,770 Reputation points MVP Moderator
    2025-04-23T22:03:08.4266667+00:00

    Here's a simple C# program that asks for your name and prints a greeting with the current time:

    using System;
    
    class Program
    {
        static void Main()
        {
            Console.Write("What's your name? ");
            string name = Console.ReadLine();
    
            string time = DateTime.Now.ToString("HH:mm:ss");
            Console.WriteLine($"Hello, {name}! The time is {time}.");
        }
    }
    

    How it works:

    • Console.Write asks for your name.
    • Console.ReadLine() reads your input.
    • DateTime.Now.ToString("HH:mm:ss") gets the current time in hours:minutes:seconds format.
    • Then it prints a greeting using your name and the current time.

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.