当我完成转换汇率的任务时,我想 return 到启动程序时出现的主菜单
When I finish my task of converting exchange rate , I want to return to the main menu that appears when I start the program
我想return到主菜单而不是重新启动程序来更改转换类型..有什么帮助吗?
如果有人帮助我,我将不胜感激..
using System;
namespace Assignment_1_Csharp
{
internal class Program
{
static void Main(string[] args)
{ int choice;
double val,EGP;
Console.WriteLine("Enter your Choice :\n 1- Dollar to EGP \n 2- EGP to Dollar ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
double dollar;
Console.Write("Enter the Dollar Amount :");
dollar = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
EGP = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} EGP", dollar, EGP);
break;
case 2:
Console.Write("Enter the EGP Amount :");
EGP = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
dollar = EGP / val;
Console.WriteLine("{0} EGP Equals {1} Dollars", EGP, dollar);
break;
}
Console.ReadLine();
}
}
}
在Console.Readline()
之后加上Main(null)
即可。
解决此问题的一种方法是使用 do-while 循环。下面的代码将 运行 通过 choice 选择和转换,然后要求用户继续。如果选择是“y”,那么它会要求用户再次选择,否则退出 main 方法。
public static void Main(string[] args)
{
int choice;
double val, EGP;
string userSelection = "y";
do
{
Console.WriteLine("Enter your Choice :\n 1- Dollar to EGP \n 2- EGP to Dollar ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
double dollar;
Console.Write("Enter the Dollar Amount :");
dollar = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
EGP = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} EGP", dollar, EGP);
break;
case 2:
Console.Write("Enter the EGP Amount :");
EGP = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
dollar = EGP / val;
Console.WriteLine("{0} EGP Equals {1} Dollars", EGP, dollar);
break;
}
Console.WriteLine("Enter Y to choose again...");
userSelection = Console.ReadLine();
}
while (userSelection.ToLower() == "y");
}
您可以将短信和选择更改为您想要的任何内容。
我想return到主菜单而不是重新启动程序来更改转换类型..有什么帮助吗? 如果有人帮助我,我将不胜感激..
using System;
namespace Assignment_1_Csharp
{
internal class Program
{
static void Main(string[] args)
{ int choice;
double val,EGP;
Console.WriteLine("Enter your Choice :\n 1- Dollar to EGP \n 2- EGP to Dollar ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
double dollar;
Console.Write("Enter the Dollar Amount :");
dollar = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
EGP = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} EGP", dollar, EGP);
break;
case 2:
Console.Write("Enter the EGP Amount :");
EGP = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
dollar = EGP / val;
Console.WriteLine("{0} EGP Equals {1} Dollars", EGP, dollar);
break;
}
Console.ReadLine();
}
}
}
在Console.Readline()
之后加上Main(null)
即可。
解决此问题的一种方法是使用 do-while 循环。下面的代码将 运行 通过 choice 选择和转换,然后要求用户继续。如果选择是“y”,那么它会要求用户再次选择,否则退出 main 方法。
public static void Main(string[] args)
{
int choice;
double val, EGP;
string userSelection = "y";
do
{
Console.WriteLine("Enter your Choice :\n 1- Dollar to EGP \n 2- EGP to Dollar ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
double dollar;
Console.Write("Enter the Dollar Amount :");
dollar = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
EGP = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} EGP", dollar, EGP);
break;
case 2:
Console.Write("Enter the EGP Amount :");
EGP = double.Parse(Console.ReadLine());
Console.Write("Enter the Dollar Exchange Rate :");
val = double.Parse(Console.ReadLine());
dollar = EGP / val;
Console.WriteLine("{0} EGP Equals {1} Dollars", EGP, dollar);
break;
}
Console.WriteLine("Enter Y to choose again...");
userSelection = Console.ReadLine();
}
while (userSelection.ToLower() == "y");
}
您可以将短信和选择更改为您想要的任何内容。