【发布时间】:2012-01-12 06:14:21
【问题描述】:
我正在开发一个程序来收集“瓶驱动器”的结果。程序会提示用户输入房间号,介于 1 和 4 之间,然后提示用户每个房间收集的瓶子数量。用户应该可以选择键入“退出”以显示每个房间和收集的瓶子数量。
这是我现在的代码,我在扩展程序以支持多个房间时遇到了困难。
namespace BottleDrive
{
class Program
{
static void Main(string[] args)
{
int roomNumber;
int numberOfBottles;
char quit;
Console.WriteLine("Enter the Room number you are in.");
string roomSelect = "";
roomSelect = Console.ReadLine();
roomSelect = int.Parse(roomSelect);
if (roomSelect >= 1)
{
Console.WriteLine("Enter the number of bottles collected by room one");
string room1Bottles = "0";
room1Bottles = Console.ReadLine();
int room1 = int.Parse(room1Bottles);
if (room1 == 1)
{
room1Bottles += room1;
Console.WriteLine("Room one has " + room1 + " many bottles collected");
}
}
if (Console.ReadLine() = quit)
{
Console.WriteLine("Room one has collected:" + room1Bottles + "\nRoom two has collected:" + room2Bottles + "Press space to quit");
string systemExit = "";
if (Console.ReadLine = "")
{
systemExit(0);
}
}
【问题讨论】:
-
我在弄清楚您要问的确切内容时遇到了一些麻烦,但我已尽力解决您的问题。更有针对性的问题(我在
x上遇到问题)比仅仅发布您的代码并要求我们修复它要好得多,所以如果您有一个具体的问题,这是一个很好的起点。 -
由于您是 C# 新手,您可能想熟悉的东西是 try and catch。例如,您可能希望将 int.Parse() 包装在 try catch 块中,以防用户输入不适合整数的内容。应用程序不会高兴。
-
我不明白为什么这里有一个
C标签。
标签: c# debugging overloading