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

Practical Exam

This document is a C# program for a simple calculator created by John Andrei Digman. It allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, and division, while also handling division by zero. The program prompts the user for two numbers and an operation choice, then displays the result or an error message accordingly.

Uploaded by

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

Practical Exam

This document is a C# program for a simple calculator created by John Andrei Digman. It allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, and division, while also handling division by zero. The program prompts the user for two numbers and an operation choice, then displays the result or an error message accordingly.

Uploaded by

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

/*

* Created by SharpDevelop.
* User: Andy
* Date: 10/01/2024
* Time: 3:08 pm
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;

namespace Test2
{
class Program
{
public static void Main(string[] args)
{
/* Introduction */

Console.Write("This is a simple calculator . . . ");


Console.WriteLine("\nMade by: John Andrei Digman Date:
01-10-24");
Console.WriteLine("Section: G11 - Nelson Mandela");
Console.Write("--------------------- ");

/* Enter number */

Console.Write("\nEnter first number: ");


int num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
int num2 = Convert.ToInt32(Console.ReadLine());

/* Operands */

Console.WriteLine("\nList of available operands: ");


Console.WriteLine("\n1: + (Addition)");
Console.WriteLine("2: - (Subtraction)");
Console.WriteLine("3: * (Multiplication)");
Console.WriteLine("4: / (Division)");
Console.WriteLine("5: Exit");
Console.Write("\nEnter your choice: ");
int symbol = Convert.ToInt32(Console.ReadLine());

/* Conditionals */

if (symbol == 1)
{ int num3 = num1 + num2;
Console.WriteLine("The sum is: "+num3); }
else if (symbol == 2)
{ int num3 = num1 - num2;
Console.WriteLine("The difference is: "+num3); }
else if (symbol == 3)
{ int num3 = num1 * num2;
Console.WriteLine("The product is: "+num3); }

/* Secret message for people dividing by 0 */

else if (num2 == 0 && symbol == 4)


{ Console.WriteLine("You can't divide by 0! "); }
else if (symbol == 4)
{ int num3 = num1 / num2;
Console.WriteLine("The quotient is: "+num3); }

/* Dividing by zero as an exit */

else if (symbol == 5)
{ int numexit = symbol - 5;
int num3 = num1 / numexit;
Console.WriteLine("Exiting program..."); }

// Thank you Tchr. Miko! :)

Console.Write("Press any key to continue . . . ");


Console.ReadKey(true);
}
}
}

You might also like