Assignment 1 APT1030 A
Assignment 1 APT1030 A
SOLUTION
using System;
namespace FunctionsExample
{
class Program
{
public static int Add(int x, int y)
{
int total = x + y;
return total;
}
public static int Subtract(int x, int y)
{
int subtraction = x * y;
return subtraction;
}
public static int Multiply(int x, int y)
{
int Multiplication = x - y;
return Multiplication;
}
public static int Divide(int x, int y)
{
int Division = x / y;
return Division;
}
static void Main(string[] args)
{
int a, b, X, Y,Z,T;
int choice;
Console.Write("Number 1: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Number 2: "); b =
Convert.ToInt32(Console.ReadLine());
Console.Write("=========Enter a choice============= \n");
Console.Write("1. Add \n");
Console.Write("2. Subtract \n");
Console.Write("3. Multiply \n");
Console.Write("4. Divide \n");
Console.Write("5. Exit \n");
Console.Write("=========Enter a choice============= \n");
choice = Convert.ToInt32(Console.ReadLine());
switch(choice)
{ case 1:
X = Add(a, b);
Console.WriteLine("{0} + {1} = {2}", a, b, X);
break; case 2:
Y = Subtract(a, b);
Console.WriteLine("{0} - {1} = {2}", a, b, Y);
break; case 3:
Z = Multiply(a, b);
Console.WriteLine("{0} * {1} = {2}", a, b, Z);
break; case 4:
T = Divide(a, b);
Console.ReadKey();
}
}
}