Write the following code using c #,1. Write a method with the following specifications: name: DisplayMenu arguments: none return value: none tasks: display the following menu choice on the screen Calculation Menu, developed by StudentID:xxxx B) Calculate Number E) To Exit Enter the Letter that corresponds to your choice: Please update your ID in the menu. You don’t have to implement the functionalities of the various menu choices at this stage Call this method from your main. 2. Modify your main so that the above method is call repeatedly. The program will terminate when the user enters E. Any other choice should produce an error message. Because you will not be doing any arithmetic you may accept the user response either as an int, or a char or a string.
时间: 2023-07-03 13:13:26 浏览: 48
Here's the C# code for the given problem:
```
using System;
class Program
{
static void Main(string[] args)
{
char choice;
do
{
DisplayMenu();
choice = Console.ReadLine().ToUpper()[0];
switch (choice)
{
case 'B':
Console.WriteLine("Calculate Number");
break;
case 'E':
Console.WriteLine("Exiting the program...");
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
} while (choice != 'E');
}
static void DisplayMenu()
{
Console.WriteLine("Calculation Menu, developed by StudentID:xxxx");
Console.WriteLine("B) Calculate Number");
Console.WriteLine("E) To Exit");
Console.Write("Enter the Letter that corresponds to your choice: ");
}
}
```
In this program, we define a method called `DisplayMenu` that displays the menu on the screen. We also modify the `Main` method to repeatedly call the `DisplayMenu` method and prompt the user for their choice. The program will exit when the user enters 'E'. Any other choice will produce an error message.