Question

Create a program using C#, more specific a calculator where the user chooses addition, subtraction, addition....

Create a program using C#, more specific a calculator where the user chooses addition, subtraction, addition. MUST use a FUNCTION, or METHOD. Each function use addition, subtraction, etc.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C# console application using functions

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static double add(double x,double y)
{
return x + y;
}
static double sub(double x, double y)
{
return x - y;
}
static void Main(string[] args)
{
Console.WriteLine("=====Calculator=========");
int ch;
double a, b,c;
while(true)
{
Console.WriteLine("Press 1 for addition");
Console.WriteLine("Press 2 for subtraction");
Console.WriteLine("Press 3 for exit");
Console.WriteLine("Enter option");
ch = Convert.ToInt32(Console.ReadLine());

if(ch==1)
{
Console.Write("Enter 1st number: ");
a= Convert.ToDouble(Console.ReadLine());
Console.Write("Enter 2nd number: ");
b = Convert.ToDouble(Console.ReadLine());
c = add(a, b);
Console.WriteLine("addtion of {0} and {1} is: {2}", a, b, c);
}
else if(ch==2)
{
Console.Write("Enter 1st number: ");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter 2nd number: ");
b = Convert.ToDouble(Console.ReadLine());
c = sub(a, b);
Console.WriteLine("subtraction of {0} and {1} is: {2}", a, b, c);
}
else if(ch==3)
{
Environment.Exit(0);
}
}

}
}
}

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

Output

Ouick Launch (Ctri-o) D ConsolcApplication1 (Running) Microsoft Visual Studio File Edit ViewProject l Debug Team Tools Test A

Add a comment
Know the answer?
Add Answer to:
Create a program using C#, more specific a calculator where the user chooses addition, subtraction, addition....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Assembly Language (MIPS), design a program calculator that can perform the following: Addition, Subtraction, Multiplication,...

    Using Assembly Language (MIPS), design a program calculator that can perform the following: Addition, Subtraction, Multiplication, Division, Power and Square Root Functions. Code must be able to accept floating point as well.

  • Description: In the main program create a menu system that will allow a user to choose...

    Description: In the main program create a menu system that will allow a user to choose from 3 option. 1. Fraction calculator 2. Grading schema 3. Biggest integer Program #1 Fraction calculator: You will start by prompting the user for two fractions in the main. The inputs should be two strings in the form #/#. You must account for both positive and negative numerators. Therefor -#/# is also a valid input. In a separate function create a program that will...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • Write a program to create a set operation calculator applying object oriented programming principles discussed in...

    Write a program to create a set operation calculator applying object oriented programming principles discussed in the class so far. The set operation calculator need to be enclosed inside one class with different methods responsible for performing the different operations listed below. When the constructor (def __init__() ) is called during object instantiation, two separate objects of this class need to be instantiated two sets S1 and S2. These two set objects can be instantiated from two python lists taken...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • The assignment In this assignment you will take the Matrix addition and subtraction code and modify...

    The assignment In this assignment you will take the Matrix addition and subtraction code and modify it to utilize the following 1. Looping user input with menus in an AskUserinput function a. User decides which operation to use (add, subtract) on MatrixA and MatrixB b. User decides what scalar to multiply MatrixC by c. User can complete more than one operation or cancel. Please select the matrix operation 1- Matrix Addition A+ B 2-Matrix Subtraction A-B 3Scalar Multiplication sC 4-Cancel...

  • Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with...

    Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with 2 integer type numbers a) Ask user what type of operation to perform (+, , * or/) a. If the user inputs 'none' then the program terminates. Otherwise it will keep continuing the calculation. (hint: use while) b) Ask user to provide 2 integer number inputs c) Perform operation (whatever operation they mentioned in a) d) Print result e) In division operation, perform a...

  • Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...

    Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...

  • Write a calculator program using JavaScript in HTML in the same HTML file. (There will only...

    Write a calculator program using JavaScript in HTML in the same HTML file. (There will only be 1 HTML file containing everything that you use for this program.) *************JavaScript Functions should be written in the HTML <head> .............. </head> tag, **************** (Please be mindful of the formatting of the text of your program. Meaning that do not copy paste everything in a single line. Add clear comments for a better understanding of your program) as follows Assignment: create a form...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT