0% found this document useful (0 votes)
21 views

C Sharpe Program

The program takes in two numbers and an operation code from the user, performs the mathematical operation on the numbers based on the code, and displays the result. It allows the user to calculate the sum, difference, product, or quotient of the numbers by selecting the corresponding code 1-4, and handles invalid code entries.

Uploaded by

Scaliba Taylor
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

C Sharpe Program

The program takes in two numbers and an operation code from the user, performs the mathematical operation on the numbers based on the code, and displays the result. It allows the user to calculate the sum, difference, product, or quotient of the numbers by selecting the corresponding code 1-4, and handles invalid code entries.

Uploaded by

Scaliba Taylor
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

class DiscountProgram
{
static void Main()
{
int num1, num2, code, sum, diff, prod;
double quotient;
Console.Write("Please enter the first number: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the second number: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n\nPlease make a selection");
Console.WriteLine("Press 1 ---> Sum");
Console.WriteLine("Press 2 ---> Difference");
Console.WriteLine("Press 3 ---> Product");
Console.WriteLine("Press 4 ---> Quotient");
code = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("The two number entered were {0} and {1}, the code enter {2}. ",
num1, num2, code);
switch (code)
{
case 1:
sum = num1 + num2;
Console.Write("The sum is:"+sum);
break;
case 2:

diff = num1 - num2;


Console.Write("The Difference is:" + diff);
break;
case 3:
prod = num1 * num2;
Console.Write("The Product is:" + prod);
break;
case 4:
if (num2 != 0)
{
quotient = num1 / num2;
Console.Write("The Quotient is:" + quotient);
}
break;
default:
Console.WriteLine("Error Code entered");
break;
}
Console.ReadKey();
}
}

You might also like