static void Main(string[] args)
{
int[] hours = new int[31];
const decimal HOURLY_RATE = 2.5M;
const decimal MAX_FEE = 20.00M;
decimal pay;
int counter = 0;
string line;
StreamReader fileSR = new StreamReader("hours.txt");
line = fileSR.ReadLine();
while (line != null)
{
hours[counter] = int.Parse(line);
counter = counter + 1;
line = fileSR.ReadLine();
}
fileSR.Close();
Console.WriteLine("hours pay");
for (int i = 0; i < hours.Length; i++)
{
pay = hours[i] * HOURLY_RATE;
Console.WriteLine("{0,4} {1,10}", hours[i], pay.ToString("C"));
}
Console.ReadKey();
}
}
}
如果超过10小时,程序需要在付费栏中显示20 $
答案 0 :(得分:0)
如果我理解正确,你需要不超过20:
pay = Math.Min(hours[i] * HOURLY_RATE, MAX_FEE);