Sunday, 8 September 2013

How can I show the history of my Operation in Console Application?

How can I show the history of my Operation in Console Application?

This is my class Arithmetic:
namespace Overloadingmethod
{
class Arithmetic
{
int operate;
public int Operate
{
get { return operate; }
set { operate = value; }
}
int num1;
public int Num1
{
get { return num1; }
set { num1 = value; }
}
int num2;
public int Num2
{
get { return num2; }
set { num2 = value; }
}
int sum;
public int Sum
{
get { return sum; }
set { sum = value; }
}
double diff;
public double Diff
{
get { return diff; }
set { diff = value; }
}
decimal product;
public void arithmetic()
{
bool option = true;
while (option)
{
Console.Write("Enter your first number: ");
try
{
num1 = Convert.ToInt32(Console.ReadLine());
break;
}
catch
{
Console.Clear();
Console.Write("Your input is not a number! Try again.");
Console.ReadLine();
Console.Clear();
option = true;
}
}
while (option)
{
Console.Write("Enter your second number: ");
try
{
num2 = Convert.ToInt32(Console.ReadLine());
break;
}
catch
{
Console.Clear();
Console.WriteLine("Your input is not a number! Try again.");
Console.ReadLine();
Console.Clear();
option = true;
}
}
}
public void Compute(int sum, int number1, int number2)
{
operate = num1 + num2;
Console.Write("\nThe sum is " + operate);
}
public void Compute(double diff, int number1, int number2)
{
operate = num1 - num2;
Console.Write("\nThe difference is " + operate);
}
public void Option()
{
char operation;
bool choice = true;
while (choice)
{
arithmetic();
Console.WriteLine("\nChoose operation:\n[A] - Addition\n[B] -
Subtraction");
Console.Write("Enter operation: ");
try
{
operation = char.Parse(Console.ReadLine().ToUpper());
if (operation == 'A')
{
Compute(Sum, Num1, Num2);
Console.ReadLine();
break;
}
if (operation == 'B')
{
Compute(Diff, Num1, Num2);
Console.ReadLine();
break;
}
else
{
Console.Clear();
Console.WriteLine("Unknown input!! Try again.");
Console.ReadLine();
Console.Clear();
choice = true;
}
}
catch
{
Console.Clear();
Console.WriteLine("Unknown input!! Try again.");
Console.ReadLine();
Console.Clear();
choice = true;
}
}
}
public void Program()
{
bool option = true;
while (option)
{
Option();
char yn;
Console.Write("\nWould you like to continue? [Y/N]: ");
yn = char.Parse(Console.ReadLine().ToUpper());
if (yn == 'Y')
{
Console.Clear();
option = true;
}
else if (yn == 'N')
{
char choice;
Console.Write("Enter 'H' to show the history and 'X' to
exit the program: ");
choice = char.Parse(Console.ReadLine().ToUpper());
if (choice == 'H')
{
int[] array = new int[5];
for (int i = 0; i < array.Length; i++)
{
Console.Write(operate);
Console.ReadLine();
}
}
if (choice == 'X')
{
option = false;
}
}
else
{
Console.Clear();
Console.WriteLine("Unknown input!! Try again.");
Console.ReadLine();
Console.Clear();
option = true;
}
}
}
}
}
and this is my Program:
namespace Overloadingmethod
{
class Program
{
static void Main(string[] args)
{
Arithmetic a = new Arithmetic();
a.Program();
}
}
}
I want to show the last five history of my Operation in my C# project if I
enter "H".
Just like if I add two numbers it will show me that I add them and then
show the result also.
But my codes is not working.
Any help please?

No comments:

Post a Comment