3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string userName = "";
            int userAge = 0;
            int currentYear = 0;

            Console.Write("Please enter your name: ");
                userName = Console.ReadLine();
            Console.Write("Please enter your age: ");
            userAge = Convert.ToInt32(Console.ReadLine());
            Console.Write("Please enter the current year: ");
            currentYear = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Hello World, my name is {0} and I'm {1} years old, I was born on the year {2} .", userName, userAge, currentYear - userAge);
        }
    }
}

It is missing the last Console.WriteLine for some reason, after I enter the currentYear, it closes the application without displaying the string to the console. Im just now starting to learn c# so also any other sources to help me learn are also welcome, thanks! (btw im using visual studio)

badjuice
  • 65
  • 1
  • 6
Zach
  • 61
  • 7
  • Please try adding a Console.Read() or Console.ReadLine() at the end of your Main method – AarónBC. May 03 '18 at 02:46
  • Welcome to [so] Zeeeee, Im glad you were able to get a first question answered! Please consider taking the time to do the [tour] and read some of whats in the [help]. Happy coding! – D. Ben Knoble May 03 '18 at 03:13

1 Answers1

9

You need to add Console.Read or Console.ReadLine at the bottom of your code

Console.ReadLine();

Or else the console will close because the blocks of codes has already been executed.

Side Note : Possible Duplicate of this Question Why is the console window closing immediately without displaying my output?

keysl
  • 2,127
  • 1
  • 12
  • 16