Answer to Question #346710 in C# for Jauani

Question #346710



1. Create a button control that has the caption Close. Now write the code which will ask the user to confirm whether he wants to close the program when he clicks on the Close button.



2. Write a program that requests the user to input two numbers and select an arithmetic operator. The program will then perform the calculation using the selected operator. (Use the Switch construct)



1
Expert's answer
2022-05-31T10:03:25-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter first number: ");
            int a = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter second number: ");
            int b = Convert.ToInt32(Console.ReadLine());


            Console.WriteLine("Enter operation: ");
            string op = Console.ReadLine();

            switch (op)
            {
                case "+": Console.WriteLine("{0} + {1} = {2}", a, b, a + b);break;
                case "-": Console.WriteLine("{0} - {1} = {2}", a, b, a - b); break;
                case "*": Console.WriteLine("{0} * {1} = {2}", a, b, a * b); break;
                case "/": Console.WriteLine("{0} / {1} = {2}", a, b, a / (double)b); break;
            }

            Console.ReadLine();
        }
    }
}

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