我不太确定要使用什么类型的循环,类功率点并没有真正说明问题,我不知道该怎么做
{
string name;
double sales;
//start loop here to ask user for employee info
name =GetName("name");
//Start a loop here to ask for the sales of each day
sales1 = GetSales("day 1 sales");
sales2 = GetSales("day 2 sales");
sales3 = GetSales("day 3 sales");
sales4 = GetSales("day 4 sales");
sales5 = GetSales("day 5 sales");
Console.WriteLine("\n");
//End loop here asking for sales of each day
Employee emp1 = new Employee( );
Display(emp1);
//End loop here asking for employee info
在之前的程序中,我们使用了
{
name = GetInput("name");
grade1 = int.Parse(GetInput("first grade"));
grade2 = int.Parse(GetInput("second grade"));
grade3 = int.Parse(GetInput("third grade"));
}
public static string GetInput(string temp)
{
Console.Write("Please enter your {0}: ", temp);
return Console.ReadLine();
}
让用户输入多个数字和一个名字,但我的教授想要循环,但我不知道如何将其转换为循环
答案 0 :(得分:2)
将字符串放入数组并使用for循环
答案 1 :(得分:2)
我会像这样使用string array和for loop:
string name = "name" ;
string names = "names";
string named = "named";
string nameds = "nameds";
string[] strArray = new string[] { name, names, named, nameds };
for (int i = 0; i < strArray.Length; i++)
{
MessageBox.Show(strArray[i].ToString());
}
注意:您需要将变量更改为满足您要求的内容,而MessageBox
只是为了向您展示字符串是否已填充到数组中并通过for loop
。
答案 2 :(得分:1)
我会使用while循环
退出条件为,而用户没有按“退出”,您可以退出等于值
答案 3 :(得分:1)
这适合一名员工
double sales[] = new double[5];
for(int i = 0; i < 5; i++) {
sales[i] = GetSales("day " + (i + 1) + " sales");
Console.WriteLine("\n");
}
Employee emp = new Employee();
扩展此解决方案以满足您的需求。