Answer to Question #289190 in C# for Chitti

Question #289190

Amit wants to develop an arithmetic calculator to perform some arithmetic functions. Develop a program to achieve the same

1
Expert's answer
2022-01-20T16:16:53-0500
using System;

namespace Calculator
{
    internal class Program
    {
   static void Main(string[] args)
        {
 
            bool quit = false;
            bool flag = false;
 
            float first = 0;
            float second = 0;
 
            char operation = '\0';
 
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine();
            Console.WriteLine(" + : Addition of number");
            Console.WriteLine(" - : Number subtraction");
            Console.WriteLine(" * : Multiplication of numbers");
            Console.WriteLine(" / : Division of numbers");
            Console.WriteLine(" q : Exit from the program ");


            Console.ForegroundColor = ConsoleColor.Green;
            do
            {
                try
                {
                    Console.Write("\nEnter a first number: ");
                    first = float.Parse(Console.ReadLine());
 
                    Console.Write("Enter a second number: ");
                    second = float.Parse(Console.ReadLine());
 
                    Console.Write("specify the operation: ");
 
                    operation = char.Parse(Console.ReadLine());
                }
                catch
                {
                    flag = true;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\aRead the instructions carefully!!!");
                    Console.ForegroundColor = ConsoleColor.Green;
                }
 
 
                if(!flag)
                {
                    switch (operation)
                    {
                        case '+': Console.WriteLine("The sum of the numbers is: " + (first + second));break;
                        case '-': Console.WriteLine("The difference between the numbers is: " +(first - second));break;
                        case '*': Console.WriteLine("The product of the numbers is: " + (first * second));break;
                        case '/': Console.WriteLine("The ratio of the numbers is: " + (first / second));break;
                        case 'q': quit = true; break;
                        default:
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\aRead the instructions carefully!!!");
                                Console.ForegroundColor = ConsoleColor.Green;
                            } 
                            break;
                   }
                }
 
                flag = false;
 
            }
            while(!quit);
 
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS