Question

In: Computer Science

In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...

In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result.

The program should continue running so the user can perform multiple operations. For example, if the user wants to add, subtract, and then multiply they should be able to do each of these without exiting the program. If you need a reference use the simple calculator on your computer. You do not need to include a function for clearing the result.

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

using System;

public class Calculator
{
   static public void Main ()
   {
       Console.WriteLine("Welcome to C# Calculator..!");
       while(true)
       {
       Console.Write("\nEnter number1: ");
       int number1 = Convert.ToInt32(Console.ReadLine());
      
       Console.Write("Enter operator (+,-,*,/) : ");
       char op = Console.ReadKey().KeyChar;
      
       Console.Write("\nEnter number2: ");
       int number2 = Convert.ToInt32(Console.ReadLine());
      
       switch (op)
       {
       case '+':
Console.WriteLine(number1+" + "+number2+" = "+(number1+number2));
break;
  
case '-':
Console.WriteLine(number1+" - "+number2+" = "+(number1-number2));
break;
  
case '*':
Console.WriteLine(number1+" * "+number2+" = "+(number1*number2));
break;
  
case '/':
Console.WriteLine(number1+" / "+number2+" = "+number1/number2);
break;
  
default:
Console.WriteLine("Not a valid operation..!");
break;
}
Console.Write("Do you want to continue? (Y/N): ");
char choice=Console.ReadKey().KeyChar;
if(choice=='N')
break;
       }
   }
}

=================


Related Solutions

Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery. The charges are based on each 500 miles shipped. Shipping charges are not pro-rated;...
What is the primary reason that addition and subtraction are considered more complex than multiplication and...
What is the primary reason that addition and subtraction are considered more complex than multiplication and division with floating-point representations? What are subnormal numbers, and how do subnormal numbers help reduce the impact of underflow?
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The program will add, subtract, multiply, or divide 2 numbers and provide the average of multiple numbers inputted from the user. You need to define a function named performCalculation which takes 1 parameter. The parameter will be the operation being performed (+,-,*,/). This function will perform the given prompt from the user for 2 numbers then perform the expected operation depending on the parameter that’s...
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT