我试图使用一种方法来计算汇率,然后将该参数传回给main中的方法。我不确定我是否已经正确地转换了钱,因为我无法弄清楚在主要调用方法时要将参数放入参数中。C#Tryinig在if/else语句中执行汇率并将参数传递到主函数中的方法参数
例如: 交换(不知道在这里放什么);
也不确定我是否正确地完成了交换方法。该程序运行到了询问用户要交换什么货币的那个点,但是只有当我注释掉交换方法时。真的卡住了,任何提示?
我想我可能要值分配给每个货币瑞典克朗,美元,欧元,但不知道从那里做...
任何帮助将不胜感激!
(如果我enetered我的代码错在这个问题上我很抱歉,真的不知道如何使它看起来任何清洁剂)
----这是一个控制台应用程序----
class Program
{
static void Main(string[] args)
{
writeMenu();
//exchange();
//exchange(choiceFromCurrency, coiceToCurrency, valueToExchange);
Console.ReadKey();
}
public static void writeMenu()
{
Console.WriteLine("Welcome to your next level Currency Converter!");
Console.WriteLine("---We---Change---Your---Money---For---You---");
Console.WriteLine(" -------So---You---Dont---Have---To!-------\n\n");
Console.WriteLine("What is your base currency?\n");
Console.WriteLine("1 = SEK, 2= USD or 3= EUR?");
string userInput = Console.ReadLine();
if (userInput == "1")
{
Console.WriteLine("You have chosen SEK (Swedish Krona)\n");
}
else if (userInput == "2")
{
Console.WriteLine("You have chosen USD (United States Dollar)\n");
}
else
{
Console.WriteLine("You have chosen EUR (Euro)\n");
}
Console.WriteLine("Which currency would you like to change your money to?\n");
string userInput2 = Console.ReadLine();
if (userInput2 == "1")
{
Console.WriteLine("You have chosen SEK (Swedish Krona)\n");
}
else if (userInput2 == "2")
{
Console.WriteLine("You have chosen USD (United States Dollar)\n");
}
else
{
Console.WriteLine("You have chosen EUR (Euro)\n");
}
}
public static decimal exchange(decimal currencyToExchangeFrom, decimal currencyToExchangeTo)
{
Console.WriteLine("How much would you like to exchange?\n");
string amountToExchange = Console.ReadLine();
decimal amountToConvert = 0;
decimal.TryParse(amountToExchange, out amountToConvert);
decimal newValue;
// SEK
if(currencyToExchangeFrom == 1)
{
// SEK - SEK
if (currencyToExchangeTo == 1)
{
Console.WriteLine("You have your money, go spend it!");
}
// sek -usd
if (currencyToExchangeTo == 2)
{
newValue = amountToConvert/8.50m;
Console.WriteLine("You now have" + newValue + " in USD");
}
}
//sek - eur
if(currencyToExchangeFrom == 2)
{
amountToConvert/9.49m;
Console.WriteLine("You now have" + newValue + " in EUR");
}
// usd - eur
if (currencyToExchangeFrom == 3)
{
amountToConvert * 0.90m;
Console.WriteLine("You now have" + newValue + " in EUR");
}
主要功能didnt打印上面的顶部但是这是我不知道什么写入()的部分 - 静态无效的主要(字符串[]参数)) { writeMenu(; exchange(); ----这里---- Console.ReadKey(); } – molebox
如果您只需要一键录入,我会在程序的第一部分查看Console.ReadKey(true) - 更容易过滤掉不需要的按键,允许ESC退出,并且不会' t要求用户按ENTER) –
@ShannonHolsinger我有Console.ReadKey();在节目结束时进行。当我要求他们想要转换多少钱时,用户将希望输入多个键。 – molebox