How can I set up three methods in C# that takes a user input and does math on the input?

how to take input from user in c# windows application
how to get string input from user in c# console application
c# read keyboard input
how to take input from user in visual studio
how to get integer input from user in c# console application
c# console.writeline multiple variables

This is a beginner's assignment, so I understand people not wanting to just give me the answer. But if possible, I'd appreciate being pointed in the right direction, as I'm very stuck on this prompt:

In a console app project, in a class file, I need to create an object called "Operator." It has to have three methods linked to it, one each for addition, subtraction and division. The program file must ask the user to type an integer, which is then passed through each method and then returned as a result to the console. They didn't specify what to add/subtract/divide by, so I'm going to use Method 1 to add "4" to user input, Method 2 to subtract "3",and last method to divide by "1".

The object is supposed to have its own cs file, and the methods are supposed to be created and called within the program file. I know there's a way to put both class and method in the same file, but for this assignment they want them separate.

I assumed the operator object shouldn't have any properties, since it doesn't have characteristics that I can think of; it's just an abstract object that does things with numbers. So I set up a really simple operator object with nothing in it but the class name:

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

namespace threemethods
{
    public class Operator
    {

    }
}

I realize this is likely wrong so far, but I don't know what else needs to be in the class file since the methods will all be in the program file. Now, where I'm really struggling is the program. I don't know where to put everything because none of examples I've seen involve user input, and most are not done externally. I know Console.WriteLine("Pick a number") will probably go in the main method, and addition/subtraction/division will be separate methods below the main one. But other than this, I have no idea the template that this should follow. I'm also unsure how to "pass" the result from one method to the next until all methods have been used. Again, I'm not expecting it to be done for me, but I really need guidance on how to approach this in order to get me going. Even a general outline of where things should go would really help. My program code is so much of a mess right now that I can't share it, as it makes no sense.

Thank you so much!

To Amir:

Thank you so much for your help! Could you explain more on how to format the Console code you've written in order to call the methods? The reason I'm confused is that we are taught to use this format for the program.cs file:

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

namespace threemethods
{
    class Program
    {
     static void Main(int[] args)

And then the main method underneath that. So, I'm not sure how to correctly integrate your console code when the format the school gives me is a little different. If I place your console code within a program file, can you tell me what code I should add to yours in order to make the program work? For example, what do I write at the top of the file before the Console code?

Thank you so much!! Sorry if what I said is confusing!


Update:

This is cs file about Console:

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

namespace Test
{
    class Program
    {
        public int Data { get; set; }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter input:");
            string line = Console.ReadLine();

            var operatorObject = new Operator(); //You have to add reference, If is not.
            var result = operatorObject.GetAdd(data);

            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}

Now in this Operator.CS file:

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

namespace threemethods
{
    public class Operator
    {
        public double GetAdd(int data)
        {
             data = data + 4;
             return GetSubtract(data);
        }    

        private  double GetSubtract(double data)
        {
             data = data - 3;
             return GetDivide(data);
        }

        private  double GetDivide(double data)
        {
             return data / 3;
        }
    }
}

For do this issue, you have to set private 2 last method, and work with one of them like my sample.

With this sample, you can call just one of the methods and develop so easy.

If you want I can create more sample for you.

Implementing User Input in C# Programming, This article focuses on user input, how you can handle different data types, and returning a with user input using the console, because these applications are the easiest to set up and configure. If the user decides to close the program, it does not crash the machine. Why not take an online class in C# Programming? 4 How can I set up three methods in C# that takes a user input and does math on the input? Sep 30 '18 2 How can I fix this syntax to add a class and style to an Html.ActionLink?


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

namespace threemethods
{
 public class Operator
 {
    public int Add(int data, int value)
    {
         return data + value;
    }    

    public int Subtract(int data, int value)
    {
        return data - value;
    }

    public int Divide(int data, int value)
    {
         return data / value;
    }
 }
}

Note that the all methods are returning an integer. Change it to some floating value if needed.

The main function:

Console.WriteLine("Enter input:");
var userValue = Convert.ToInt32(Console.ReadLine());

var operatorObject = new Operator();
var result = operatorObject.Add(userValue, 4);
result = operatorObject.Subtract(result, 3);
result = operatorObject.Divide(result, 1);

Console.WriteLine(result);
Console.ReadLine();

C# User Input, WriteLine() is used to output (print) values. Now we will use Console.ReadLine() to get user input. In the following example, the user can input his or hers  To use a value returned from a method, the calling method can use the method call itself anywhere a value of the same type would be sufficient. You can also assign the return value to a variable. For example, the following two code examples accomplish the same goal: int result = obj.AddTwoNumbers(1,


The other answers have already answered the question, although you seem to be asking a new question about how to implement the answered code? You already hit the nail on the head on the edit to your question, the answer from either above that you prefer (Amir's or Philipp's) is simply written in the main class you've already made! Using Amir's as an example:

using System;

namespace threemethods
{

    public class Operator
    {
        public double GetAdd(int data)
        {
            data = data + 4;
            return GetSubtract(data);
        }

        private double GetSubtract(double data)
        {
            data = data - 3;
            return GetDivide(data);
        }

        private double GetDivide(double data)
        {
            return data / 3;
        }
    }
    class Program
    {
        public static int Data { get; set; }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter input:");
            string line = Console.ReadLine();
            Data = Int32.Parse(line);
            var operatorObject = new Operator();
            var result = operatorObject.GetAdd(Data);
            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}

Note, you would've thrown an error on main as the arguments for a console entry point are Main(string[] args) and not Main(int[] args). VS doesn't like it if you change this! Also, I recommend not bloating your imports with stuff you don't need. Only using System, only import System. Just because it's default doesn't mean it's needed. Further, using the Data field setup is interesting and not how I would've done it, you probably don't need it? Just using a variable in Main is easier I would think, and more readable with less code. Also, don't forget to parse the string object and convert to an int for operations!!!

This would be your example implementation! Have fun.

Methods, Overview of methods, method parameters, and method return values. type to which the method belongs; static methods do not operate on instance data. 3); } static int Square(int i) { // Store input argument in a local variable. int input = i; public override int Drive(int miles, int speed) { return (int) Math. All three of our methods have two parameters. In C#, you can set a default value for each parameter. Variables with default values must be at the end of the parameter list. Let's take a look at some sample code. public class Calculator { private int m_result = 0; public Calculator() { } public int Add(int num1, int num2 = 0) { m_result = num1 + num2;


C# Basic Input and Output, In this tutorial, we will learn how to take input from user and and display output in C# using various methods. I am doing an exercise that allows the user to input a bid amount for an item. I need to include 3 overloaded methods (int, double, string). (The exercise says to use double not decimal.) I know how to write the overloaded methods, my confusion comes with the user input.


Methods in C# - working with CSharp methods, It is a good programming practice that methods do only one specific task. Methods bring two methods. One of them takes two parameters, the other one takes three parameters. At this moment, the program waits for an input from the user. Say we have a set of data, for example salaries of employees. To use a value returned from a method, the calling method can use the method call itself anywhere a value of the same type would be sufficient. You can also assign the return value to a variable. For example, the following two code examples accomplish the same goal: int result = obj.AddTwoNumbers(1,


Computing with C# and the .NET Framework, Do Exercise 9 of Chapter 3 (Write a C# program that computes the weekly 3 (​Write a C# program that checks a grade point average the user inputs, and Compare your result with the value produced by the Sqrt method of the Math class. A method is a group of statements that together perform a task. Every C# program has at least one class with a method named Main. To use a method, you need to − Define the method. Call the method. Defining Methods in C# When you define a method, you basically declare the elements of its structure. The syntax for defining a method in C# is as