using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Menu_Attempts
{
class Program
{
static void Main(string[] args)
{
bool forever = true;
do
{
Console.WriteLine("1. Stone to Pounds");
Console.WriteLine("2. Quit");
int reply = Convert.ToInt32(Console.ReadLine());
switch (reply)
{
case 1:
Console.WriteLine("Enter an amount in Stone");
double UserInput = double.Parse(Console.ReadLine());
StoneToPounds(UserInput);
break;
case 2:
Console.WriteLine("You've decided to quit.");
forever = false;
break;
}
} while (forever);
}
public static double StoneToPounds(double number)
{
double answer = number * 14;
return answer;
}
}
}
所以我试图做一个基于控制台的菜单,并在需要时调用方法来清理它。我选择选项1.将石头转换为磅,它给了我一个输入数字的选项。但是,当我这样做时,只是回到菜单的乞讨?C#在switch语句中没有被调用的方法?
您从不输出/写入StoneToPounds()的结果... –
你没有对StoneToPounds的返回值做任何事情。它会被调用,你只是没有看到它的任何输出,你的while while循环然后再次按预期启动 – Thewads
'Console.WriteLine(StoneToPounds(UserInput));'? –