我正在尝试做一个程序,该程序接受三个首字母 A、B、C 之一的输入(让我们说三个家庭首字母),然后提示输入数字(销售额)。该程序需要不断要求另一个三个初始数字,然后再要求另一个数字。最后,当用户键入 Z 时,程序结束,但显示每个家庭的总销售额。
对于如何设置这样的程序,我有很多麻烦。
朝着正确的方向轻推会很棒。
http://postimg.org/image/9heb6c403/
如果你想看问题
是的,它的控制台底座。展示代码感觉很糟糕,但是
string QUIT = "Z";
string quit = "z";
string purchaseString;
string mainString;
double salesA = 0;
double salesB = 0;
double salesC = 0;
string andr1 = "a";
string andr2 = "A";
string bow1 = "b";
string bow2 = "B";
string clax1 = "c";
string clax2 = "C";
double purchase;
Console.WriteLine("To begin press anykey. To see total enter Z or Z ");
mainString = Console.ReadLine();
while ((mainString == andr1 || mainString == andr2) || mainString != QUIT && mainString != quit)
{
Console.WriteLine("Enter the persons Intials: ");
mainString = Console.ReadLine();
if (mainString == andr1 || mainString == andr2)
{
Console.Write("Enter next purchase amount: ");
purchaseString = Console.ReadLine();
purchase = Convert.ToDouble(purchaseString);
salesA += purchase;
}
if (mainString == bow1 || mainString == bow2)
{
Console.Write("Enter next purchase amount: ");
purchaseString = Console.ReadLine();
purchase = Convert.ToDouble(purchaseString);
salesB += purchase;
}
if (mainString == clax1 || mainString == clax2)
{
Console.Write("Enter next purchase amount: ");
purchaseString = Console.ReadLine();
purchase = Convert.ToDouble(purchaseString);
salesC += purchase;
}
}
Console.WriteLine("Total for Anderson, Bowman and Claxton respectively is {0} {1} {2}", salesA.ToString("c"), salesB.ToString("c"), salesC.ToString("c"));
Console.ReadLine();
}
}
}
有没有另一种方法来启动它
Console.WriteLine("开始按任意键。要查看总数,请输入 Z 或 Z"); mainString = Console.ReadLine(); while ((mainString == andr1 || mainString == andr2) || mainString != QUIT && mainString != quit)
似乎没有必要