Question

Write a C# program (Integer Math Calculator, the programming requirements are as follows: When typing in...

Write a C# program (Integer Math Calculator, the programming requirements are as follows:

When typing in 3+4, 10-5, 12*12, 15/5 from console, the program should give the right answers on screen like 7, 5, 144, 3.

This is what I have so far:

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
String input;
do
{
Console.Write("Type int values to calulate or stop to exit: ");
input = Console.ReadLine();
if (input.ToLower() != "stop")
{
char[] delimiters = { '-', '+', ',', '+', '-', '*', '/' };
String[] tokens = input.Split(delimiters);
int Math = 0;
foreach (String token in tokens)
Math += int.Parse(token);
Console.WriteLine("The sum is: " + Math);

}
} while (input.ToLower() != "stop"); // compare strings
}
}
}

I am trying to get the subtraction, multiplicaton, and divison to fit in above to make it work. Please show work. Thanks

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

i have written full code for a calculator

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Arithmetic_Operators

{

    class calculator

    {

        static void Main(string[] args)

        {

            int num1, num2;

            int add, sub, mul;

            float div;

            //get values from users

            Console.Write("Enter number 1\t\t");

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

            Console.Write("\n\nEnter number2\t\t");

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

  

            //adding values

            add = num1 + num2;

            // subtracting values

            sub = num1 - num2;

            //multiplying values

            mul = num1 * num2;

            //r dividing values

            div = (float)num1 / num2;

            //print Output

            Console.WriteLine("\n\n=====================\n");

            Console.WriteLine("Addition\t\t{0}", add);

            Console.WriteLine("Subtraction\t\t{0}", sub);

            Console.WriteLine("Multiplication\t\t{0}", mul);

            Console.WriteLine("Division\t\t{0}", div);

            Console.WriteLine("\n=======================\n");

            Console.ReadLine();

        }

    }

}

Add a comment
Know the answer?
Add Answer to:
Write a C# program (Integer Math Calculator, the programming requirements are as follows: When typing in...
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
  • Could anybody give me comment here to help me understand this code? please, I want details...

    Could anybody give me comment here to help me understand this code? please, I want details comment. thank you in advance using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Framing { class Program { static void Main(string[] args) { Dictionary charEncoding = new Dictionary(); charEncoding.Add("A", "01000111"); charEncoding.Add("B", "11100011"); charEncoding.Add("C", "11000001"); charEncoding.Add("ESC", "11100000"); charEncoding.Add("FLAG", "01111110"); Console.WriteLine("Enter Sequence: "); string input = Console.ReadLine().Trim().ToUpper(); Console.Write("Byte count: " + Convert.ToString((input.Split(' ').Length + 1), 2).PadLeft(8, '0')); foreach (string str in input.Split(' '))...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • Greetings everyone I am having a little trouble with this one. I bolded my switch case...

    Greetings everyone I am having a little trouble with this one. I bolded my switch case which should work but its currently not. If a user selected course option 1 twice it just says you enrolled in course 1 and course 1. It should stop it by executing case -2. Need a new set of eyes. - Thanks using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleRegisterStudent { class Program { static void Main(string[] args) { (new...

  • C#, I am getting error placing them all in one file pls set them in the...

    C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null;    }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...

  • (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example,...

    (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example, if a user inputs a repeated number the program should regenerate or ask to enter again. If needed, here is the program requirements: Create a lottery game application. Generate four random numbers, each between 1 and 10. Allow the user to guess four numbers. Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess,...

  • Please Write the following program in c# You are to write an application which will create...

    Please Write the following program in c# You are to write an application which will create a company, add agents (their name, ID, and weekly sales) to that company, and printout the details of all agents in the company. The application will contain three classes: Agent.cs, Company.cs, and CompanyTest.cs (this class is already provided). Flow of the application: The CompanyTest class creates an object of the Company class and reserves space for five agents. At this point if you call...

  • C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that...

    C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that line N times. That is, output a square of N lines each with N characters. Example output for parameters N=5 and S="*" should appear as follows: 多多本事事 串串串串串 事事事串串 事事事事事 2. Modify the DrawChars method so that the number of the line appears at that position within the line. That is, line i must have N-1 copies of S with the additional character in...

  • You are to write a program that implements a Reverse Polish Notation Calculator in C using...

    You are to write a program that implements a Reverse Polish Notation Calculator in C using BISON and FLEX, You only have to edit the BISON and FLEX files. Link to the files to start and have a general view of the program: https://www.dropbox.com/sh/83yzs66jhftqj5b/AABZcY9Qwl84JdUFnYpQaZk9a?dl=0 Reverse Polish Notation is a mathematical notation in which every operator follows all of its operands. It is sometimes called postfix notation, and does not require any parentheses as long as each operator has a fixed...

  • So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

    So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...

  • You must first compile both .cs file into .exe. Then, run the server in one command...

    You must first compile both .cs file into .exe. Then, run the server in one command prompt window and run two cilents, each in a separate command prompt window. To quit a client, you may enter no book title but just hit the enter or enter Ctrl-C. The server always displays a message whenever a client is connected and disconnected. <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key = "U101" value="PHYSICS"/> <add key = "U102" value="EDU"/> <add key = "U103"...

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