基于输入输出类别的C#控制台应用程序
我的任务是开发一个windows应用程序,该应用程序收集员工信息:作为输入的销售项目的名称和数量,并输出信息摘要,根据销售项目的数量(低于50个项目、50-99个项目、100-199个项目和高于199个项目)对销售人员进行分组,见下文。你能帮我查一下这个密码吗。以下是我目前使用的代码:基于输入输出类别的C#控制台应用程序,c#,list,if-statement,arraylist,C#,List,If Statement,Arraylist,我的任务是开发一个windows应用程序,该应用程序收集员工信息:作为输入的销售项目的名称和数量,并输出信息摘要,根据销售项目的数量(低于50个项目、50-99个项目、100-199个项目和高于199个项目)对销售人员进行分组,见下文。你能帮我查一下这个密码吗。以下是我目前使用的代码: using System; namespace L0002B { public class Salesperson { string Name { get; set; }
using System;
namespace L0002B
{
public class Salesperson
{
string Name { get; set; }
int Quantity_Sold { get; set; }
static void Main(string[] args)
{
System.Collections.Generic.List<Salesperson> Salesperson = new System.Collections.Generic.List<Salesperson>()
{
new Salesperson {Name="Donald Duck ", Quantity_Sold=173},
new Salesperson {Name="Mickey Mouse ", Quantity_Sold=202},
new Salesperson {Name="Snoopy ", Quantity_Sold=203},
};
}
private static void Bonus(ref int Quantity_Sold)
{
if (Quantity_Sold >= 200)
{
Console.WriteLine("Above 199 items");
}
else if (Quantity_Sold >= 100)
{
Console.WriteLine("100-199 items");
}
else if (Quantity_Sold >= 50)
{
Console.WriteLine("50-99 items");
}
else
{
Console.WriteLine("Below 50 items");
}
Console.WriteLine("Bonus Report: " Bonus);
}
}
}
使用系统;
名称空间L0002B
{
公开课销售员
{
字符串名称{get;set;}
int数量_销售{get;set;}
静态void Main(字符串[]参数)
{
System.Collections.Generic.List Salesperson=new System.Collections.Generic.List()
{
新销售人员{Name=“唐老鸭”,销售数量=173},
新销售人员{Name=“米老鼠”,销售数量=202},
新销售人员{Name=“Snoopy”,销售数量=203},
};
}
私人静态无效奖金(参考整数数量\已售出)
{
如果(销售数量>=200)
{
控制台。写线(“199项以上”);
}
否则,如果(销售数量>=100)
{
控制台写入线(“100-199项”);
}
否则,如果(销售数量>=50)
{
控制台写入线(“50-99项”);
}
其他的
{
控制台。写线(“低于50项”);
}
Console.WriteLine(“奖金报告:奖金”);
}
}
}
我想要一个输出,它提供了一个类似这样的报告,但我得到了一个空白的输出。
您的if条件有两个问题
if (Quantity_Sold < 50)
...
else if (Quantity_Sold > 50)
...
if (Quantity_Sold < 50)
...
else if (Quantity_Sold > 50)
...
If.将多个阈值与
进行比较。。否则,如果
,则必须从最大值开始。如果您正在与进行比较,您面临的问题是什么?那么,如果值为120,该怎么办?它高于50,因此触发分支,忽略任何其他分支@HansKesting您的问题仍然没有说明您所面临的问题。if和else的逻辑可以通过ZoharPeled发布的答案来确定。你还面临什么问题?我已经在问题中添加了错误信息。主要是系统不识别销售人员名单。我已应用此更正,我的输出仍为空blank@HassBonus()
是代码中创建任何输出的唯一方法。但是我没有看到你在任何地方调用它…我已经编辑了问题中的代码,但是当我调用它时,我得到了这个错误。“语法错误,”,“预期(CS1003)(L0002B)”您预期Console.WriteLine(“奖金报告:奖金”)代码>要做什么?首先,必须通过,
分隔方法调用中的两个参数。其次,您必须从Main
方法调用Instance的Bonus
方法,最好是针对每个销售人员。TBH:如果你缺乏基本的编程技巧(例如如何调用方法),我不确定我能帮你什么。您可能应该先学习一些基本的编程教程。
if (Quantity_Sold > 50)
... //this will be hit because 123 > 50
else if (Quantity_Sold > 100)
... //this won't be hit anymore because first condition already is hit
if (Quantity_Sold >= 100)
... // 100 .. maxint
else if (Quantity_Sold >= 50)
... // 50 .. 99
else
... // 0 .. 49