Write a program for a calculator that will be able to perform addition, subtraction, multiplication and division. Make a main menu. It should take float values from user as inputs and display outputs as a string after performing selected operation.
Solution:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace calculator { class Program { static void Main(string[] args) { float a, b,c, result; Console.WriteLine("Add Sub Mult Div\n "); Console.WriteLine("Enter the a"); a = float.Parse(Console.ReadLine()); Console.WriteLine("Enter the b"); b = float.Parse(Console.ReadLine()); Console.WriteLine("1 for Add\n 2 for Sub\n 3 f0r Mult\n 4 for Div\n "); Console.WriteLine("Enter the c"); c = float.Parse(Console.ReadLine()); if (c==1) { result= a + b; Console.WriteLine(result); } if (c==2) { result = a - b; Console.WriteLine(result); } if (c==3) { result = a * b; Console.WriteLine(result); } if (c==4) { result = a / b; Console.WriteLine(result); } Console.ReadLine(); } } }
Post A Comment:
0 comments: