この問題を解決する方法を見つけようとサイトを掘り下げました。私はC#の初心者ですから、初心者の質問にお答えしたら謝ります。私は従業員クラスと2つの新しい従業員インスタンスを作成しましたが、最初の従業員情報のみが動作します
私達はちょうど私があまりにも面倒見つからないもの、私たちのコースで授業を始めました。しかし、私たちの最初の割り当てでは、従業員の賃金引き上げ率とパーセンテージを取るクラスEmployeeを作成しました。メインプログラムでは、2つの新しいインスタンスe1とe2を作成します。私は、GetValueメソッドを使用して従業員のデータを読み込みます。私の問題は、それは1人目の従業員にとって素晴らしいことですが、2人目の従業員の入力を求めないことです。 e1とe2の両方のデータを読み込んで出力するにはどうすればよいですか?
私は両方の従業員のための入力を取得するために行うことができますいくつかのループまたは反復はありますか?事前に
おかげで、 ダイアン
は、ここに私のコードです:
//identify the variables
string firstName, lastName, employeeID, department;
decimal salary;
firstName = GetValue("First Name");
lastName = GetValue("Last Name");
employeeID = GetValue("Employee ID");
department = GetValue("Employee Department");
salary = Convert.ToDecimal(GetValue("Salary"));
//create two employee objects
Employee e1 = new Employee(firstName, lastName, employeeID, salary, department);
Employee e2 = new Employee(firstName, lastName, employeeID, salary, department);
//get user input
//clear the screen
Console.Clear();
//Display the pay rise information
Console.WriteLine("Total increase in salary for employee 1 is {0}", e1);
Console.WriteLine("Total increase in salary for employee 2 is {0}", e2);
Console.ReadLine();
}//end of Main
static public string GetValue(string value)
{
Console.WriteLine("Please enter the {0} >>", value);
string input = Console.ReadLine();
return input;
}//end GetValue
あなたは両方の 'Employee'に全く同じ値を指定しています - あなたは2番目の' Employee'の新しい入力を要求していません。 – UnholySheep