0% found this document useful (0 votes)
23 views2 pages

CALCULATOR

The document outlines a simple console-based calculator application that allows users to perform basic arithmetic operations: addition, subtraction, multiplication, and division. It prompts the user for two numbers and an operation choice, then displays the result. The Calculator class defines methods for each arithmetic operation but contains some errors in parameter handling and variable usage.

Uploaded by

Osama Rashayda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

CALCULATOR

The document outlines a simple console-based calculator application that allows users to perform basic arithmetic operations: addition, subtraction, multiplication, and division. It prompts the user for two numbers and an operation choice, then displays the result. The Calculator class defines methods for each arithmetic operation but contains some errors in parameter handling and variable usage.

Uploaded by

Osama Rashayda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MAIN Method

Calculator calc = new Calculator();

do
{
Console.WriteLine("Please input two numbers");
int X = Convert.ToInt32(Console.ReadLine());
int Y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please choose the following you want to do");
Console.WriteLine("1. Add");
Console.WriteLine("2. Minus");
Console.WriteLine("3. Mult");
Console.WriteLine("4. Div");
int number = Convert.ToInt32(Console.ReadLine());
switch (number)
{
case 1:
Console.WriteLine("Your result is" + calc.Add(num1, num2));
break;
case 2:
Console.WriteLine("Your result is" + calc.Subtract(num1, num2));
break;
case 3:
Console.WriteLine("Your result is" + calc.Multiply(num1, num2));
break;
case 4:
Console.WriteLine("Your result is" + calc.Divide(num1, num2));
break;
default:
Console.WriteLine("Please input again");
break;
}
a = Console.ReadLine();
}
while (a == "y");

CLASS File

private int x;
private int y;

public Calculator()
{

}
public Calculator(x, y)
{

// Adds two numbers and returns the sum


public int Add(x, x)
{
return x + y;
}

// Difference between two numbers


public int Subtract(x, y)
{
return x - y;
}

// Multiplies two numbers and returns the result


public int Multiply(x, y)
{
return num1 * num2;
}

// Performs division on two numbers


public int Divide(x, y)
{
return x / y;
}

You might also like