Posted 12 years ago
·
Author
This is meant for C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab2TakeInputData
{
/* This program takes input of name
* it then takes age input
* Finally displays it as one statement
*/
class Program
{
static void Main(string[] args)
{
// this line displays enter your name
Console.WriteLine("Enter your name ");
// this line takes input from the end user
string SomeDatafromUser = Console.ReadLine();
try
{
// this line checks if the name is not greater than 10
if (SomeDatafromUser.Length > 10)
{
throw new Exception("Your name should not be greater than 10 characters");
}
// this line displays enter your age text
Console.WriteLine("Enter your age");
int Age = 0;
// this line takes age input
Age = Convert.ToInt16(Console.ReadLine());
// this line displays the complete statement with data entered
Console.WriteLine("Hello Mr " + SomeDatafromUser + " your age is " + Age);
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
}
}