Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CALCULATOR LAB Programming Review Design and write a caleulator progran uaing th

ID: 3747500 • Letter: C

Question

CALCULATOR LAB Programming Review Design and write a caleulator progran uaing the following requirenents 1) The Program mast inelude and display the following menu to the user 1-Add 2Subtract Multiply Divide 2) The program should only exit when the user enters O(zero) 3) The progran mast print the result in equation form )The program mast prevent the user from dividing by zero 5) The progran should display "Invalid selection" if the user choses menu option that is less than or greater than 4. 6) All arithretie operations will use tvo nunbers ) The should prompt the user to provide nunbers for the selected operation This must be done in C#

Explanation / Answer

Explanation::

Code in C# ::

using System;

class Calculator {

public static void Main (string[] args) {

Console.WriteLine ("___________________Calculator Lab___________________");

while(true){

/**

* Following we print the Menu

*/

Console.WriteLine("0 - Quit 1 - Add 2 - Subtract 3 - Multiply 4 - Divide ");

/**

* Below we ask user to enter the choice and the value is stored in variable choice.

*/

Console.Write("Your choice ::");

int choice = Convert.ToInt32(Console.ReadLine());

if(choice==0){

/**

* If choice is 0 then we break the while loop

*/

Console.WriteLine("______________________Bye Bye______________________");

break;

}else if(choice>=0 && choice<=4){

/**

* Here an char variable named op is declared that stores the value of

* '+' , '-' , '*' , '/' depending on the choice of user.

*/

char op;

/**

* Two variables named num1 and num2 are declared below that stores the value of

* two numbers entered by user

*/

int num1,num2;

/**

* An double variable named answer is declared below that stores the final result of operation.

*/

double answer=0;

/**

* Below we ask user to enter num1 and num2 separately.

*/

Console.Write("Enter number 1::");

num1=Convert.ToInt32(Console.ReadLine());

Console.Write("Enter number 2::");

num2=Convert.ToInt32(Console.ReadLine());

if(choice==1){

/**

* Addition

*/

op='+';

answer=num1+num2;

}else if(choice==2){

/**

* Subtraction

*/

op='-';

answer=num1-num2;

}else if(choice==3){

/**

* Multiply

*/

op='*';

answer=num1*num2;

}else{

/**

* Divide

*/

op='/';

if(num2==0){

Console.WriteLine("Cannot divide by Zero!");

continue;

}

answer=(double)num1/num2;

}

Console.WriteLine(num1+" "+op+" "+num2+" = "+answer);

}else{

Console.WriteLine("Invalid selection");

}

Console.WriteLine("________________________________________________");

}/*While loop ends here*/

}/*Main method ends here*/

}/*Class ends here*/

OUTPUT::

Please provide the feedback!!

Thank You!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote