Click here to Skip to main content
13,191,400 members (72,026 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int userAge;
Console.Write("Please enter your age: ");
userAge = Convert.ToInt32(Console.ReadLine());

if (userAge < 0 || userAge > 100)
{
Console.WriteLine("Invalid Age");
Console.WriteLine("Age must be between 0 and 100");

}
else if (userAge < 18)
Console.WriteLine("Sorry you are underage");
else if (userAge < 21)
Console.WriteLine("You need parental consent");
else
{
Console.WriteLine("Congratulations!");
Console.WriteLine("You may sign up for the event");
}

}
}
}
it runs fune, but the application disappeared automatically once I hit enter.... how can I solve it?

What I have tried:

debug s'ConsoleApp1.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ConsoleApp1.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'c:\users\li fei\documents\visual studio 2017\Projects\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.exe'. Symbols loaded.
The program '[12264] ConsoleApp1.exe' has exited with code 0 (0x0).
Posted 19-Jun-17 8:57am
Updated 19-Jun-17 9:10am
Comments
Richard MacCutchan 20-Jun-17 3:38am
   
Run it in a command Window, or use Ctrl-F5.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Use a Console.ReadKey() or Console.ReadLine() at the end of Main().
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171017.1 | Last Updated 19 Jun 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100