Write a C# program (Integer Math Calculator, the programming requirements are as
ID: 3838315 • Letter: W
Question
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
Explanation / Answer
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 ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write(" Enter number2 ");
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(" ===================== ");
Console.WriteLine("Addition {0}", add);
Console.WriteLine("Subtraction {0}", sub);
Console.WriteLine("Multiplication {0}", mul);
Console.WriteLine("Division {0}", div);
Console.WriteLine(" ======================= ");
Console.ReadLine();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.