Click here to Skip to main content
14,937,212 members
Please Sign up or sign in to vote.
1.00/5 (1 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
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

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

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900