namespace Assignment02
{
class assigement02question04
{
public static void answer()
{
//declare variables: ID number = int, rate of pay, number of hours , overtime , gross pay = double
//disply what is your employee ID number
//catpure ID number
//disply what is your rate of pay
//catpure rate of pay
//disply what is the number of hours you have worked
//catpure number of hours worked
//display what is the amount of over time hours
//catpure over time hours
//Calculate gross pay = (number of hours + over time x 1.5) x rate of pay
//calculate net pay = gross pay - gross pay x 0.33 - 25 (convert to currency)
//disply ID number , number of hours , rate of pay , over time hours and gross pay
//declare variables
int ID_Number;
double rate_of_pay;
double number_of_hours;
double over_time;
double gross_pay;
double net_pay;
//input your employee ID
Console.Write("What is your employee ID number? ");
ID_Number = int.Parse(Console.ReadLine());
//input your rate of pay
Console.Write("What is your rate of pay? ");
rate_of_pay = double.Parse(Console.ReadLine());
//input number of hours
Console.Write("What is the number of hours you have worked? ");
number_of_hours = double.Parse(Console.ReadLine());
//input over time hours
Console.Write("What is the amount of over time hours? ");
over_time = double.Parse(Console.ReadLine());
//intput of our gross pay
gross_pay = (number_of_hours + over_time * 1.5) * rate_of_pay;
//input of our net pay
net_pay = gross_pay - gross_pay * .33 - 25;
net_pay = Math.Round(net_pay, 2);
//Disply as end result
Console.WriteLine("Your employee ID number is: " + ID_Number);
Console.WriteLine("The number of regular hours is: " + number_of_hours);
Console.WriteLine("The number of O/T hours is: " + over_time);
Console.WriteLine("The rate of pay of is: " + rate_of_pay);
Console.WriteLine("Your gross pay is: $" + gross_pay);
Console.WriteLine("Your net pay is: $" + net_pay);
Console.ReadLine();
}
}
}
質問する
350 次
1 に答える
0
Decimal を使用することをお勧めしますが、醜いレガシー コードにパッチを当てるだけで苦労している場合に備えて、質問に答えるには、次のようなものを使用できます。
public decimal ToMoney(double Input) {
int _precision = 2;
decimal _result;
try{
double multiplier = Math.Pow(10, Convert.ToDouble(_precision));
_result = System.Convert.ToDouble(Math.Ceiling(input * multiplier) / multiplier);
} catch {}
return _result;
}
次に呼び出します。
string CurrencySymbol = "$";
Console.WriteLine("The rate of pay of is: " + CurrencySymbol +
ToMoney(rate_of_pay).ToString());
...幸せなコーディング。
于 2012-09-23T18:09:03.260 に答える