Question

In: Computer Science

Using c# , Write a program using a switch statement that takes one character value from...

Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /)

If not the program display a message that it not of the operators ( (+, -, * , /) .

Solutions

Expert Solution

The required code and corresponding output are as follows. The code is well commented for better understanding.

using System;
using System.Collections.Generic;
using System.Text;
namespace Arithmetic
{
    class Arithmetic
    {
        static void Main(string[] args)
        {
            char op;// declare operator
            Console.Write("Enter the character: ");
            op = Convert.ToChar(Console.ReadLine());//reads operator
            switch (op)//enters in switch structure
            {
            case '+':
                Console.WriteLine(op + " is an arithmetic operator");
                break;
            case '-':
                Console.WriteLine(op + " is an arithmetic operator");
                break;
            case '*':
                Console.WriteLine(op + " is an arithmetic operator");
                break;
            case '/':
                Console.WriteLine(op + " is an arithmetic operator");
                break;
            default:
                Console.WriteLine(op + " is not an arithmetic operator");
                break;
            }
            Console.ReadLine();
        }
 
    }
}

Output:


Related Solutions

***Using Java Using the switch/case construct, write a program that takes a character from the user...
***Using Java Using the switch/case construct, write a program that takes a character from the user and classifies it as a number (‘1’,’2’, ‘3’, …), a letter from the alphabet (‘A’, ‘a’, ‘B’, ‘b’, …, ‘Z’, ‘z’), an arithmetic operator (‘+’, ‘-‘, ‘/’, ‘*’, ‘%’), a comparison operator (‘<’, ‘>’, ‘=’), punctuation (‘!’, ‘?’, ‘,’, ‘,’, ‘:’, ‘;’), and all other characters as a Special Character, and informs the user of the same. If the user entered the character A,...
Write a program in C or in Java, that takes an integer value N from the...
Write a program in C or in Java, that takes an integer value N from the command line, generates N random points in the unit square, and computes the distance separating the closest pair of points. A unit square is a square with sides of length 1, at points (0, 0), (0, 1), (1, 0), and (1, 1). If you wish to avoid the command-line processing, you can just assume you will generate a fixed number of points, say between...
Write a C program that takes a double value and rounds it up or off using...
Write a C program that takes a double value and rounds it up or off using ternary expression in the program. Example, if -2.5 is inputted the value should give -3.0
Use a switch statement to write a function that returns TRUE if a character is a...
Use a switch statement to write a function that returns TRUE if a character is a consonant and returns FALSE otherwise.
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based...
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based on your input and the selection from the keyboard, the program does the followings. If the selection is 1, the program should test the input if it’s positive, negative or zero. For example, the output should be “The selection is 1 to test the input value if it’s positive, negative or equal to zero. The input value 7 is positive” If the selection is...
In C++, The following program reads one character from the keyboard and will display the character...
In C++, The following program reads one character from the keyboard and will display the character in uppercase if it is lowercase and does the opposite when the character is in uppercase. If the character is a digit, it displays a message with the digit. Modify the program below such that if one of the whitespaces is entered, it displays a message and tells what the character was. // This program reads one character from the keyboard and will //...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character argument/ parameter called "phone" and returns a double. When the variable argument phone contains the caracter a or A, print the word Apple and return 1099.99. When phone contains the caracter s or S print the word Samsung and return 999.99. When phone contains anything else, return 0.0.
Write a batch program that takes and echoes input data one character at a time until...
Write a batch program that takes and echoes input data one character at a time until EOF is encountered and then prints a summary such as The 14 lines of text processed contained 20 capital letters, 607 lowercase letters, and 32 punctuation marks. Program: C
Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
With C code Write a switch statement (not a complete program) which prints an appropriate message...
With C code Write a switch statement (not a complete program) which prints an appropriate message for a letter code entered. Use the following messages: If L is entered, output the message "Lakers" If C is entered, output the message "Clippers" If W is entered, output the message "Warriors" If any other character is entered, output the message "invalid code" Make sure to handle the case where the user enters in a small letter. That is, a capital or small...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT