Dibawah ini adalah contoh program Exception HAndling dalam C#.
using System;
namespace Exception_Handling_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int r,x;
string status;
double []p=new double[5];
double []q=new double[5];
double []mean=new double[5];
string []name= new string[50];
try
{
Console.Write("How Many Students? ");
r=Convert.ToInt32(Console.ReadLine());
for (x=0;x<r;x++)
{
Console.WriteLine("\nData ke-{0}",x+1);
Console.Write("Name : ");
name[x]=Console.ReadLine();
Console.Write("Mid Exam : ");
p[x]=Convert.ToDouble(Console.ReadLine());
Console.Write("Final Exam : ");
q[x]=Convert.ToDouble(Console.ReadLine());
}
for (x=0;x<r;x++)
{
mean[x]=(p[x]+q[x])/2;
}
Console.WriteLine("\n\n");
Console.WriteLine("No\tName\t\tMid Exam\tFinal Exam\tAverage\t\tStatus");
Console.WriteLine("------------------------------------------------------------------------------");
for (x=0;x<r;x++)
{
if (mean[x]>=60)
{
Console.WriteLine("{0}\t{1}\t\t{2}\t{3}\t{4}\t\tOke",x+1,name[x],p[x],q[x],mean[x]);
}
else
{
Console.WriteLine("{0}\t{1}\t\t{2}\t{3}\t{4}\t\tNot Oke",x+1,name[x],p[x],q[x],mean[x]);
}
}
}
catch
{
Console.WriteLine("Inputan salah!");
}
Console.ReadLine();
}
}
}
Subscribe to:
Post Comments (Atom)
1 comments:
ok, just checking. Radix
Post a Comment